Vista Task Dialog

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: Vista Task Dialog

Post by Rescator »

SFSxOI wrote:This doesn't seem to be working though:

Code: Select all

<a href="+#DQUOTE$+"http://purebasic.com/"+#DQUOTE$+">PureBasic</a>"
Were you trying to put a clickable link there?
It works. but only on Vista+ :)
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Vista Task Dialog

Post by SFSxOI »

Yes, your correct. It will only work with the task dialog on Vista and above because the methods i've outlined here using task dialog's are only for Vista and above.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Vista Task Dialog

Post by Denis »

Here are structures TASKDIALOG_BUTTON / TASKDIALOGCONFIG for both x_86/x_64 plateform.

Code: Select all

Structure TASKDIALOG_BUTTON
     nButtonID.l
     *pszButtonText
EndStructure

Structure TASKDIALOGCONFIG
     cbSize.l
     hwndParent.i
     hInstance.i
     dwFlags.l
     dwCommonButtons.l
     *pszWindowTitle
     StructureUnion
          hMainIcon.i
          *pszMainIcon
     EndStructureUnion
     *pszMainInstruction
     *pszContent
     cButtons.l
     *pButtons.TASKDIALOG_BUTTON
     nDefaultButton.l
     cRadioButtons.l
     *pRadioButtons.TASKDIALOG_BUTTON
     nDefaultRadioButton.l
     *pszVerificationText
     *pszExpandedInformation
     *pszExpandedControlText
     *pszCollapsedControlText
     StructureUnion
          hFooterIcon.i
          *pszFooterIcon
     EndStructureUnion
     *pszFooter
     *pfCallback
     *lpCallbackData
     cxWidth.l
EndStructure
for hMainIcon.i / hFooterIcon.i, i 've tried with .l under x_64 without problem (i use hMainIcon) but I am not sure of its type.
A+
Denis
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Vista Task Dialog

Post by Tomi »

can u make an example for your code?
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Vista Task Dialog

Post by Denis »

Tomi wrote:can u make an example for your code?
I just pick SFSxOI piece of code up. I've changed the 2 structures.
I use a prototype instead of CallFunctionFast.
I use PB functions to get lib adress instead API.
I remove a procedure wich create unicode string, you must compile it in unicode mode (Vista limitation).

under x_64, if you put the old structures, nothing will happend. In my project, it crashs.
That'all and it rocks under x_64/x_86.

The

Code: Select all

CompilerIf #PB_Compiler_Unicode
  CompilerElse
    MessageRequester("Error", "You have To compile it in unicode mode", 16)
    End
CompilerEndIf

Define .i
#IDOK = 1
#IDCANCEL = 2
#IDABORT = 3
#IDRETRY = 4
#IDIGNORE = 5
#IDYES = 6
#IDNO = 7
#IDCLOSE = 8

#TD_WARNING_ICON = -1
#TD_ERROR_ICON = -2
#TD_INFORMATION_ICON = -3
#TD_SHIELD_ICON = -4

#TD_ICON_BLANK = 100
#TD_ICON_WARNING = 101
#TD_ICON_QUESTION = 102
#TD_ICON_ERROR = 103
#TD_ICON_INFORMATION = 104
#TD_ICON_BLANK_AGAIN = 105
#TD_ICON_SHIELD = 106


Structure TASKDIALOGCONFIG
     cbSize.l
     hwndParent.i
     hInstance.i
     dwFlags.l
     dwCommonButtons.l
     *pszWindowTitle
     StructureUnion
          hMainIcon.i
          *pszMainIcon
     EndStructureUnion
     *pszMainInstruction
     *pszContent
     cButtons.l
     *pButtons.TASKDIALOG_BUTTON
     nDefaultButton.l
     cRadioButtons.l
     *pRadioButtons.TASKDIALOG_BUTTON
     nDefaultRadioButton.l
     *pszVerificationText
     *pszExpandedInformation
     *pszExpandedControlText
     *pszCollapsedControlText
     StructureUnion
          hFooterIcon.i
          *pszFooterIcon
     EndStructureUnion
     *pszFooter
     *pfCallback
     *lpCallbackData
     cxWidth.l
EndStructure

Structure TASKDIALOG_BUTTON
     nButtonID.l
     *pszButtonText
EndStructure

; Structure TASKDIALOG_BUTTON
;      nButtonID.l
;      pszButtonText.l
; EndStructure
; 
; Structure TASKDIALOGCONFIG
;      cbSize.l
;      hwndParent.l
;      hInstance.l
;      dwFlags.l
;      dwCommonButtons.l
;      pszWindowTitle.l
;      StructureUnion
;           hMainIcon.l
;           pszMainIcon.l
;      EndStructureUnion
;      pszMainInstruction.l
;      pszContent.l
;      cButtons.l
;      pButtons.l
;      nDefaultButton.l
;      cRadioButtons.l
;      pRadioButtons.l
;      nDefaultRadioButton.l
;      pszVerificationText.l
;      pszExpandedInformation.l
;      pszExpandedControlText.l
;      pszCollapsedControlText.l
;      StructureUnion
;           hFooterIcon.l
;           pszFooterIcon.l
;      EndStructureUnion
;      pszFooter.l
;      pfCallback.l
;      lpCallbackData.l
;      cxWidth.l ;width of the Task Dialog's client area in DLU's. If 0, Task Dialog will calculate the ideal width.
; EndStructure

Dim tbButtons.TASKDIALOG_BUTTON(2)
sBtn1 = @"Heck Yeah!"
sBtn2 = @"Nope!"
sBtn3 = @"Repeat The Question?"
tbButtons(0)\nButtonID = #IDYES
tbButtons(0)\pszButtonText = sBtn1
tbButtons(1)\nButtonID = #IDNO
tbButtons(1)\pszButtonText = sBtn2
tbButtons(2)\nButtonID = #IDCANCEL
tbButtons(2)\pszButtonText = sBtn3

#ID_RADIO_BUTTON_PURE = 1002
#ID_RADIO_BUTTON_BASIC = 1003
#ID_RADIO_BUTTON_IS_NEAT = 1004
#ID_RADIO_BUTTON_FORUM = 1005

Dim ID_RADIOButtons.TASKDIALOG_BUTTON(3)
IDsBtn1 = @"Pure"
IDsBtn2 = @"Basic"
IDsBtn3 = @"Is Neat!"
IDsBtn4 = @"Go to the Purebasic Tips and Tricks Forum - select here and click the 'Heck Yeah!' button "
ID_RADIOButtons(0)\nButtonID = #ID_RADIO_BUTTON_PURE
ID_RADIOButtons(0)\pszButtonText = IDsBtn1
ID_RADIOButtons(1)\nButtonID = #ID_RADIO_BUTTON_BASIC
ID_RADIOButtons(1)\pszButtonText = IDsBtn2
ID_RADIOButtons(2)\nButtonID = #ID_RADIO_BUTTON_IS_NEAT
ID_RADIOButtons(2)\pszButtonText = IDsBtn3
ID_RADIOButtons(3)\nButtonID = #ID_RADIO_BUTTON_FORUM
ID_RADIOButtons(3)\pszButtonText = IDsBtn4


sWindowTitle = @"A Larger Task Dialog"
sMainInstruction = @"Do you want to view the larger TaskDialog?"
sContent = @"Here it is now with custom buttons."
sVerify = @"Don't show this message again"
sExpanded = @"An example provided by SFSxOI for PureBasic Tips and Tricks."
sCollapsedControlText = @"Where the heck did this come from?"
sExpandedControlText = @"Ah, got it!"

tdlg.TASKDIALOGCONFIG
tdlg\cbSize = SizeOf(tdlg)
tdlg\hwndParent = #Null
tdlg\hInstance = #Null
tdlg\dwFlags = #Null
tdlg\dwCommonButtons = #Null
tdlg\pszWindowTitle = sWindowTitle
tdlg\hMainIcon = #TD_ICON_SHIELD
tdlg\pszMainInstruction = sMainInstruction
tdlg\pszContent = sContent
tdlg\cButtons = 3
tdlg\pButtons = @tbButtons(0)\nButtonID
tdlg\cRadioButtons = 4
tdlg\pRadioButtons = @ID_RADIOButtons(0)\nButtonID
tdlg\nDefaultButton = #IDNO
tdlg\pszVerificationText = sVerify
tdlg\pszExpandedInformation = sExpanded
tdlg\pszExpandedControlText = sExpandedControlText
tdlg\pszCollapsedControlText = sCollapsedControlText
tdlg\hFooterIcon = #Null
tdlg\pszFooter = #Null
tdlg\pfCallback = #Null


;// prototype used to call TaskDialog function
Prototype TaskDialogIndirect(*tdlgx, *ClickedButtonx, *SelRadiox, *fVerifyx)

Procedure Task_DialogIndirect(tdlgx)
     Global fVerifyx, SelRadiox
     Protected *Task_Dialog_Func
     Protected *Proto_TaskDialog.TaskDialogIndirect
     
     Libef = OpenLibrary(#PB_Any, "comctl32.dll")
     If Libef
       *Task_Dialog_Func = GetFunction(Libef, "TaskDialogIndirect")
          If *Task_Dialog_Func
               ;// assign proto pointer, but you can use *Task_Dialog_Func directly if it is declared as .TaskDialogIndirect
               *Proto_TaskDialog = *Task_Dialog_Func
               ;CallFunctionFast(*Task_Dialog_Func, tdlgx, @ClickedButtonx, @SelRadiox, @fVerifyx)
               *Proto_TaskDialog(tdlgx, @ClickedButtonx, @SelRadiox, @fVerifyx)
          EndIf
     EndIf
     CloseLibrary(Libef)
     ProcedureReturn  ClickedButtonx
EndProcedure

ClickedButton = Task_DialogIndirect(tdlg)

If fVerifyx = #True
     Debug "You checked the 'Do not prompt me again' box"
     ;set some registry To indicate so, so Next time the prompt is Not shown
Else
     ;clear the registry, so Next time the prompt is shown
EndIf

If SelRadiox = #ID_RADIO_BUTTON_PURE
     SelRadio$ = "PURE radio button"
Else
     If SelRadiox = #ID_RADIO_BUTTON_BASIC
          SelRadio$ = "BASIC radio button"
     Else
          If SelRadiox = #ID_RADIO_BUTTON_IS_NEAT
               SelRadio$ = "IS NEAT! radio button"
          Else
               If SelRadiox = #ID_RADIO_BUTTON_FORUM And ClickedButton = #IDYES
                    SelRadio$ = "Go to the Purebasic Tips and Tricks Forum"
                    ShellExecute_(#Null,"open","http://www.purebasic.fr/english/viewtopic.php?t=30801",#NULL$,#NULL$,#SW_SHOWMAXIMIZED)
               EndIf
          EndIf
     EndIf
EndIf

Select ClickedButton
          
     Case #IDOK
          Debug "You clicked the OK button"
          Debug "and you also clicked the " +SelRadio$
     Case #IDCANCEL
          Debug "You clicked the Repeat Question? button"
          Debug "and you also clicked the " +SelRadio$
     Case #IDABORT
          Debug "You clicked the Abort button"
          Debug "and you also clicked the " +SelRadio$
     Case #IDRETRY
          Debug "You clicked the Retry button"
          Debug "and you also clicked the " +SelRadio$
     Case #IDIGNORE
          Debug "You clicked the Ignore button"
          Debug "and you also clicked the " +SelRadio$
     Case #IDNO
          Debug "You clicked the Nope button"
          Debug "and you also clicked the " +SelRadio$
     Case #IDYES
          Debug "You clicked the Heck Yeah! button"
          Debug "and you also clicked the " +SelRadio$
          
EndSelect
A+
Denis
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Vista Task Dialog

Post by Tomi »

many Thanks Denis
this code work on Win XP?
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Vista Task Dialog

Post by Denis »

Tomi wrote:many Thanks Denis
this code work on Win XP?
No Tomi, Vista minimum.

If i remeber, OpenLibrary(#PB_Any, "comctl32.dll") will fail.
A+
Denis
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Vista Task Dialog

Post by Tomi »

Thanks Denis, u give me an useful help :D :D :D merci
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Vista Task Dialog

Post by jacdelad »

Hi,
I get Denis' example working under x86, but not x64. Do I need a different manifest or structure?

Edit: Found out that the DLL is not loaded. But how do I fix this?
Edit2: Found it: I had to replace both "x86" in the manifest with "amd64". Jesus...
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Vista Task Dialog

Post by Denis »

Hi jacdelad,

it' working here under x64.
Just removed line 1 to 7.

I've created an exe (x64) and open it with Resource Hacker.

here is the manifest i get, and as you can see, the processorArchitecture is "amd64", nothing to change.
The manifest is defined by PB compiler.
Edit: Found out that the DLL is not loaded. But how do I fix this?
Don't really know, may be a path environnement variable problem ?

Did u use the Demo PB ?
If so, there are limitations.
Edit2: Found it: I had to replace both "x86" in the manifest with "amd64". Jesus...
Normally, you don't have to do this



[<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="amd64"
name="CompanyName.ProductName.YourApp"
type="win32" />
<description></description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="amd64"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>

</assembly>]
A+
Denis
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Vista Task Dialog

Post by jacdelad »

Hi Denis,
thanks for the answer. I am not using a demo version, I paid the full price and I'm a valuable member of the society! :D

I used the manifest from the first post in this thread. Do you mean I can use the whole code without changes to the manifest at all? Otherwise, like we both stated, changing "x86" to "amd64" was the right thing to do.

Anyway, the taskdialog is working fine now. I found out that you can use custom icons and also these command_links. Also, changing the icon constants can produce cool predefined effects, like a shield icon with red or green background. My code is a mess, but if anyone wants it I/we could make an easy-to-use module from it. I for one really like taskdialogs and compatibility for <Vista is not needed anymore.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Vista Task Dialog

Post by Denis »

jacdelad wrote: Tue May 11, 2021 9:27 pm Do you mean I can use the whole code without changes to the manifest at all?
Yes, compiling it with PB in x64 mode will set the manifest correctly, nothing more to do.
A+
Denis
Post Reply