TaskDialog() - the other 'MsgBox' for Win Vista+

Post your working scripts, libraries and tools for AHK v1.1 and older
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 02:34

MSDN wrote:Task Dialog
... A task dialog is similar to, while much more flexible than, a basic message box.
Source
The task dialog was introduced with Win Vista and the simple form TaskDialog() can be used as a 'modernized' message box replacement.

There are at least two implementations at AutoHotkey dot com:
  • TheGood's 'all-inclusive' solution wrapping the TaskDialogIndirect() function:
    :arrow: /board/topic/54555-taskdialog-stdlib-compatible/
  • nepter's solution providing wrapper functions for both TaskDialog() and TaskDialogIndirect() functions:
    :arrow: /board/topic/96587-ahk-l-taskdialog-taskdialogex-windows-vista/
Nevertheless, I think it's worth to be found here too (though according to Microsoft it won't work on Win XP). So I wrote a slightly changed wrapper for the TaskDialog() function using the main instruction as the only mandatory parameter and additional undocumented icon values found in TheGood's script.

Screenshot:
TaskDialog.PNG
TaskDialog.PNG (5.86 KiB) Viewed 17104 times
Simple version
Advanced version
Updated on 2014-09-26: see Advanced version
Last edited by just me on 26 Sep 2014, 00:48, edited 4 times in total.
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 03:28

Yes, this is cool.
If I may:
Maybe a "simpler" way to do the combination of the button. Calculating in HEX is not my strong side ;)
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 03:35

ozzii wrote: If I may:
Maybe a "simpler" way to do the combination of the button. Calculating in HEX is not my strong side ;)
You may not, because its already been done. Read the docs:
just me wrote:

Code: Select all

; Buttons:  Specifies the push buttons displayed in the dialog box (optional).
;           This parameter may be a combination of the integer keys defined in TDBTNS or a 
;           pipe (|) separated list of the string keys.
; =========================================================================================
TaskDialog(Main, Extra := 0, Title := "", Buttons := 0, Icon := 0, Parent := 0) {

   Static TDBTNS := {OK: 0x01, YES: 0x02, NO: 0x04, CANCEL: 0x08, RETRY: 0x10, CLOSE: 0x20}
   ;...
   If Buttons Is Integer
      BTNS := Buttons & 0x3F
   Else
      For Each, Btn In StrSplit(Buttons, "|")
         BTNS |= (B := TDBTNS[Btn]) ? B : 0

Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 03:45

@ozzii
TaskDialog() inline doc wrote:This parameter may be a combination of the integer keys defined in TDBTNS or a pipe (|) separated list of the string keys.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 04:17

ozzii, I've updated the script using decimal values. But you don't need to precalculate at all. You just might use TaskDialog("My Main", "My Extra", "My Title", 0x02 + 0x04).
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 04:37

Hi just me, if it's OK with you, perhaps you can provide more flexibility on the type of delimiter for the Buttons parameter other than a pipe(|). Something like StrSplit(Buttons, ["|", " ", ",", "`n"])
User avatar
huyaowen
Posts: 109
Joined: 28 Jul 2014, 01:15

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 06:18

so cool.thanks.
how can i set this beautiful msgbox alway on top?
and where is the close button?
QQ截图20140920230307.jpg
QQ截图20140920230307.jpg (54.33 KiB) Viewed 17027 times
User avatar
DataLife
Posts: 445
Joined: 29 Sep 2013, 19:52

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 11:14

TaskDialog() has 3 of the 4 icons supported by Msgbox, it is missing the Icon Question.

Is it possible to have question mark icon?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 11:24

@DataLife, it only supports the following:

Code: Select all

TD_ERROR_ICON       -> A stop-sign icon appears in the task dialog.
TD_INFORMATION_ICON -> An icon consisting of a lowercase letter i in a circle appears in the task dialog.
TD_SHIELD_ICON      -> A security shield icon appears in the task dialog.
TD_WARNING_ICON     -> An exclamation-point icon appears in the task dialog.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 17:47

Very interesting, I'll check it out!
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
huyaowen
Posts: 109
Joined: 28 Jul 2014, 01:15

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

20 Sep 2014, 19:41

Could you set 2 extra parameters for " timeout" and "alway on top"?
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

21 Sep 2014, 02:01

Coco wrote:...perhaps you can provide more flexibility on the type of delimiter for the Buttons parameter other than a pipe(|). Something like StrSplit(Buttons, ["|", " ", ",", "`n"])
Sure, I'll use your StrSplit for the next update.
huyaowen wrote:and where is the close button?
The close button only appears in combination with the cancel button.
DataLife wrote:TaskDialog() has 3 of the 4 icons supported by Msgbox, it is missing the Icon Question.
This has been discussed on MSDN too. It seems that the lack of the question mark is intended by Microsoft due to changed user interface design guidelines.
huyaowen wrote:Could you set 2 extra parameters for " timeout" and "alway on top"?
The task dialog doesn't offer equivalent options. But I'll think about a workaround.
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

21 Sep 2014, 03:09

guest3456 wrote: You may not, because its already been done. Read the docs:
I overlooked this and didn't understand it well at my first read.
So, just me, I am so sorry for having overlooked your documentation :headwall:

Oh, and thanks, for the update.
User avatar
huyaowen
Posts: 109
Joined: 28 Jul 2014, 01:15

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

21 Sep 2014, 03:44

thanks.
waiting for the update.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

22 Sep 2014, 06:06

Well, it's done. I've implemented the requested features, but decided to keep the original function as 'simple version' and to release a second 'advanced version'. The 'advanced' features are:
  • AlwayOnTop option.
  • Support for the missing question mark icon.
  • Support for custom icons.
  • New Timeout parameter.
I hope you'll like it.
User avatar
huyaowen
Posts: 109
Joined: 28 Jul 2014, 01:15

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

22 Sep 2014, 07:14

thank you very much.
Could u also import the normal msgbox for XP?
then display the beautiful msgbox on win7 or newer.and display a normal msgbox on WINXP.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

22 Sep 2014, 07:29

I think I can! ;)
User avatar
huyaowen
Posts: 109
Joined: 28 Jul 2014, 01:15

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

22 Sep 2014, 07:57

aha!so amazing!
thanks again.
Could the normal msgbox recognize the parameters(on top,icon,timeout and so on)?
Last edited by huyaowen on 22 Sep 2014, 18:18, edited 1 time in total.
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: TaskDialog() - the other 'MsgBox' for Win Vista+

22 Sep 2014, 08:32

@huyaowen:
some info for you about MsgBox
- MessageBox function
- MessageBoxEx function
- MessageBoxIndirect function & MSGBOXPARAMS structure

@just me:
something to add for Task Dialogs
About Task Dialogs (Parts of a Task Dialog)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 107 guests