Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

TaskDialog() (stdlib compatible)


  • Please log in to reply
21 replies to this topic
TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

A Task Dialog is a new kind of dialogbox that has been added in Windows Vista and later. They are similar to message boxes, but with much more power.

taskdialog.png

Although fincs already made an excellent wrapper for it, I made TaskDialog() so that it can be used in mainstream AHK. I tried to find the right balance between AHK's philosophy of user-friendliness and access to TaskDialogIndirect's powerful features.

Download

(includes documentation)

 

Examples

taskdialogexamples.png

For guidelines on how to design great Task Dialogs, read these:

 

Comments, suggestions, and more importantly bug reports are welcome!

Enjoy!

Changelog

August 22nd, 2010

- Added support for AHK_L x64

June 14th, 2010

- Added failsafe in case OS doesn't support TaskDialogs.
- Fixed legitimate text starting with double-backslashes be mistaken for resource IDs.
- Icon resource IDs must now also start with a backslash. This is both for consistency, and to avoid collisions (e.g. if the ID is "INFO").
- The script now uses the flip() function from Lazslo and SKAN here. Thanks!
- Added an extra example that uses resource IDs for all the parameters.

June 8th, 2010

- Added hParent's ability to be used as the sCallback parameter.
- Renamed the internal functions so that they are more unique.
- Optimized code size of ResolveIcon (thanks MasterFocus!).
- Added another "page" to Example 19.
- Fixed static vars not being reset if user re-opens the same example.



Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
cant believe there are no comments yet on this! this is pure awesomeness :!:

i liked fincs wrapper but stopped using it because i dont use ahk unicode
so thank you very much for this! i can finally use it on my normal ahk scripts
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

gahks
  • Members
  • 32 posts
  • Last active: Feb 23 2011 02:52 AM
  • Joined: 10 Jan 2009
And a damn neat code too. Looks interesting, thanks! :)

guest3456
  • Guests
  • Last active:
  • Joined: --

And a damn neat code too. Looks interesting, thanks! :)


agreed. i love the extensive documentation and comments

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Can't test it here (at home), but the code looks nice indeed.

Since I don't wanna sleep right now, here's a shorter version of the
last function (where I don't think performance would be a problem):
ResolveIcon(sIcon) {
  static st_Strings := "WARNING,ERROR,INFO,SHIELD,BLUE,YELLOW,RED,GREEN,GREY"
  Loop, Parse, st_Strings, `,
    If ( sIcon = A_LoopField )
      Return ( 0xFFFF - (A_Index-1) )
  Return sIcon
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
Thanks for the nice comments guy! :D
MasterFocus, awesome space optimization! :) (I highly doubt there's any performance impact)
I updated the function as well as the Examples script (added a "page" to the wizard in Example 19).

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Here's another part that can be a little bit shortened without killing readability:
;Split the icons
    StringSplit, sIcons, sIcons, |
    
    ;Check what we were given
    If ( sIcons0 >= 1 )
        iMainIcon := _TaskDialog_ResolveIcon(sIcons1)
    If ( sIcons0 >= 2 )
        iFooterIcon := _TaskDialog_ResolveIcon(sIcons2)
    If ( sIcons0 = 3 ) {
        If iMainIcon is not integer ;Check if it's a resource string
        {   TaskDialog_ANSItoWide(&iMainIcon, sMainIconW)
            iMainIcon := &sMainIconW
        }
        If iFooterIcon is not integer ;Check if it's a resource string
        {   TaskDialog_ANSItoWide(&iFooterIcon, sFooterIconW)
            iFooterIcon := &sFooterIconW
        }
        
        ;Check if it's a path (otherwise assume it's already a handle)
        If (FileExist(sIcons3))
            hModule := DllCall("LoadLibrary", "str", sIcons3, "uint"), bUnload := True
        Else hModule := sIcons3
    }
    
    ;Split the callback string
    StringSplit, sCallback, sCallback, |
    
    ;Check what we got
    If ( sCallback0 >= 1 )
        sCBFunc := sCallback1
    If ( sCallback0 = 2 )
        sCBData := sCallback2

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
I updated the function to fix a few bugs, and added an example.

June 14th, 2010

- Added failsafe in case OS doesn't support TaskDialogs.
- Fixed legitimate text starting with double-backslashes be mistaken for resource IDs.
- Icon resource IDs must now also start with a backslash. This is both for consistency, and to avoid collisions (e.g. if the ID is "INFO").
- The script now uses the flip() function from Lazslo and SKAN here. Thanks!
- Added an extra example that uses resource IDs for all the parameters.



Petru
  • Members
  • 236 posts
  • Last active: Jan 19 2012 06:47 PM
  • Joined: 17 Dec 2007
Wonderful, but this should be ported to AHK_L because it doesn't show well when Unicode.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

Wonderful, but this should be ported to AHK_L because it doesn't show well when Unicode.

I don't see the need to port it to AHK_L since fincs already made a wrapper for it. And it fully supports Unicode.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
I added support for AHK_L 64-bit, which I guess also means support for Unicode. :oops:

hoppfrosch
  • Members
  • 399 posts
  • Last active: Feb 26 2016 05:31 AM
  • Joined: 25 Jan 2006

Wonderful, but this should be ported to AHK_L because it doesn't show well when Unicode.

I don't see the need to port it to AHK_L since fincs already made a wrapper for it. And it fully supports Unicode.


fincs solution does not support WIN7 yet ...

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

fincs already made a wrapper for it. And it fully supports Unicode.

My wrapper was written in the early AutoHotkeyU days, it's not really compatible with AutoHotkey_L neither x64 and the code is messy.
Your wrapper is easier to use than mine. Great work! :D

BTW: how does the _TaskDialog_PrepSplitString() MCode work on both x86 and x64??

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Do I need Win7 for this to work :?:
It does not do anything on my XP :?

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

Your wrapper is easier to use than mine. Great work! :D

Thanks!

BTW: how does the _TaskDialog_PrepSplitString() MCode work on both x86 and x64??

Whoops... it doesn't! :shock: I forgot to recompile for x64! Thanks!

Do I need Win7 for this to work?

Unfortunately, yes. :(

A Task Dialog is a new kind of dialogbox that has been added in Windows Vista and later.