MagicBox - Message Box Generator

Post your working scripts, libraries and tools
User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

MagicBox - Message Box Generator

31 Jul 2016, 17:47

MagicBox is a development tool to assist in the creation of message boxes.

"Message boxes provide a simple, standardised method to display information, warnings and errors to the user. They can also be used to ask simple questions and to request confirmation of actions." Source

The Windows API has many message box functions, MessageBox being the most commonly used, and MagicBox is able to generate the code for a variety of such functions, including task dialogs.


:arrow: Download


Custom message box function. It offers custom buttons and icon, support for hyperlinks, verification text, font and color, callback and the look and feel of a regular message box.

Parameters: Text, [Title, Buttons, Icon, ByRef CheckText, Styles, Owner, Timeout, FontOptions, FontName, BGColor, Callback]


The MsgBox function displays a message box and waits for the user to click a button and then an action is performed based on the button clicked by the user. This is a generic description valid for any type of message box.

MsgBox, Text
MsgBox [, Options, Title, Text, Timeout]

Extended options: custom button text, icons and position.


Displays a message box that gives the user the option of suppressing further occurrences. If the user has already opted to suppress the message box, the function does not display a dialog box and instead simply returns the default value.

This function supports only a subset of the flags supported by MessageBox. The question mark icon and the "always on top" option are not available on Windows Vista and higher.

The unique ID is stored in a registry key.

Parameters: Text, [Title, Options, RegVal, Owner]


Creates, displays, and operates a message box. The message box contains application-defined message text and title, any icon, and any combination of predefined push buttons.

Parameters: Text, [Title, Options, IconRes, IconID, Owner]


SoftModalMessageBox encompasses functions like MessageBox, MessageBoxTimeout and MessageBoxIndirect. Up to 10 buttons can be defined.

Parameters: Text, Title, Buttons, [DefBtn, Options, IconRes, IconID, Timeout, Owner, Callback]


Little is known about this function.

Parameters: Text, [Title, Options, Owner]

WTSSendMessage (WinStationSendMessage)

This function can be used to display a message box from a service or on the client desktop of a specified Remote Desktop Services session. Always on top, no owner, no focus and no theme.

Parameters: Text, [Title, Options, Timeout, Wait, Session, Server, ByRef Response]


Displays a simple task dialog that contains application-defined message text and title, an icon, and any combination of predefined push buttons.

Parameters: Instruction, [Content, Title, Buttons, IconID, IconRes, Owner]


The TaskDialogIndirect function creates, displays, and operates a task dialog. The task dialog contains application-defined icons, messages, title, verification check box, command links, push buttons, and radio buttons. This function can register a callback function to receive notification messages.

The code for this function is generated "on demand": only the necessary members of the TASKDIALOGCONFIG structure are defined.

Sample scripts demonstrating TaskDialogIndirect and MsgBoxEx can be found in the Examples folder.

More functions

The following functions are included in the functions folder, but MagicBox does not generate the code for them:


Parameters: Instruction, [Content, Title, CustomButtons, CommonButtons, MainIcon, Flags, Owner, VerificationText, ExpandedText, FooterText, FooterIcon, Width]

The CustomButtons parameter is a pipe-delimited list of button labels that can be displayed as command links provided the flag 0x10 or 0x20.


This function uses MessageBox on Windows XP and TaskDialog on Vista+.

Parameters: Text, [Title, Options, Owner]

Return value

MagicBox generates the conditional statements for the return value. For most types of message box it is one of the following values: OK, Cancel, Abort, Retry, Ignore, Yes, No, Try Again, Continue and Timeout.

For SoftModalMessageBox and TaskDialogIndirect, the return value is the button ID.

For the MagicBox function, the return value is the button text with ampersands removed. If the window is dismissed with the close button in the title bar or by pressing the Esc key, the value is Cancel.

Keyboard shortcuts:
• F1: Help (MSDN links).
• F9: Displays the message box.
• F10: Opens the code window.
• Alt+F9: Displays the message box in a new instance of AHK.
• Ctrl+F9: Runs the script from the code window.

Limitations on Windows XP:
• Task dialog functions require Windows Vista or higher.
• MsgBox custom button: icon is not supported.
• SHMessageBoxCheck: only the combinations of buttons OK, OK|Cancel and Yes|No are available.
• MsiMessageBox: the font size is microscopic.

Credits to:
• Lexicos, for the function ResourceIdOfIcon.
• TheGood, for task dialog examples.
• just_me, for additional task dialog options via callback.
• A guest, for MsgBoxV2.
• Fanatic Guru, for MsgBox_XY.
• Authors of libraries in use.
• The layout of the custom buttons dialog is based on TDXML Editor.

AutoHotkey 1.1.23+ Unicode 32 or 64-bit. Tested on Windows XP, 7 and 10.
Last edited by Alguimist on 05 Jan 2018, 06:02, edited 2 times in total.
Posts: 105
Joined: 20 Jan 2014, 17:57

Re: MagicBox Factory

31 Jul 2016, 22:57

Hi Alguimist ;
Many thanks for this, been looking for some easy way to change key names. Can't get any easier then this. Just gave it a fast look, and with all those
features I don't think it can be beat. Does everything but brew my tea. Very, very nice! Thanks again, hunter99
Edit: Sorry I forgot to also thank all those listed in credits and all who took part. Thank you.
Posts: 743
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: MagicBox Factory

03 Aug 2016, 14:38

Good tool :) Thank you
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
Posts: 55
Joined: 19 May 2016, 07:44

Re: MagicBox Factory

13 Sep 2016, 15:44

This tool is perfect !!
I love these tools which make your life easier :)
Thank you !!

I downloaded your tool and successfully updated few of my messaging stuff I wrote before to different kind of %Box (more beautiful :) ). But I faced a problem now when I was changing few of my MsgBox to MagicBox, I couldn't pass the variables, even the built in ones such as %A_UserName% when I write them in my message body.
Is this a bug?
User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

Re: MagicBox Factory

15 Sep 2016, 06:36

It's something that has not been implemented. Not a bug.
User avatar
Posts: 242
Joined: 21 Aug 2016, 05:11

Re: MagicBox Factory

25 Sep 2016, 03:22

Thanks Alguimist, great tool as always from you!
User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

Re: MagicBox Factory

22 Oct 2016, 13:30


The InputBoxEx function allows the user to enter input value. The type of input control used by this function can be specified so that the input can be made by means of a ComboBox or DropDownList, a ListBox, a CheckBox, a calendar (DateTime or MonthCal), a Hotkey box, a Slider. By default, an Edit box is used.


Parameters: [Instruction, Content, Title, Default, ControlType, ControlOptions, Width, x, y, WindowOptions, Timeout, Owner]

Instruction: Text in a bigger font size to explain the user's objective with the dialog box.
Content: Descriptive information, additional details. Hyperlinks can be used.
Title: Title of the window.
Default: Initial text of the input control.
ControlType: The type of the input control.
ControlOptions: Options of the input control. For example: r3 (3 rows), number, password, checked.
Width: Optional width of the window. Height is adjusted automatically.
x and y: Coordinates. If blank or omitted, the window is centered on the screen.
WindowOptions: Options such as MinimizeBox, AlwaysOnTop and -SysMenu.
Timeout: Time (in seconds) after which the window is automatically closed.
Owner: Handle of the parent window.

The return value is the string or value selected, according to the control type. ErrorLevel is set as follows: 0 - The user pressed OK. 1 - The user pressed the Cancel button. 2 - InputBoxEx exited due to timeout.

The function and the example script are in the respective folders. MagicBox Factory does not generate the code for InputBoxEx.

:arrow: Download
Posts: 2
Joined: 05 Nov 2016, 19:29

Re: MagicBox Factory

21 Nov 2016, 18:12


Thank you for this amazing generator, I have been looking for this long ago.

Suggestion, can you add default selected button in msgbox?
User avatar
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: MagicBox Factory

22 Nov 2016, 13:03

This tool may come in handy sometimes. Nice work! :)

There may still be a few minor tweaks needed in regard to generated code. I've noticed some handles are retrieved as type Ptr and subsequently used or freed as UInt. Same with GlobaFree-ing callback pointers. This would potentially create trouble on x64 systems.

For example in SHMessageBoxCheck where hModule is retrieved as Ptr, then used in GetProcAddress as UInt, then The Owner/Desktop ternary operation is also cast to a UInt although it should be a Ptr.
In MessageBoxIndirect hModule is retrieved as Ptr at first attempt, no type definition in LoadLibraryEx() and in the end FreeLibrary() casts it as an UInt.
Same pattern in SoftModalMessageBox with Callback, where RegisterCallback() returns a pointer while GlobalFree() casts an UInt.
There may be other places I haven't checked so maybe a thorough code review would be advisable.

The MsiMessageBox is a hard nut to crack. Behaves differently on two similar XP-SP3 systems.
One has msi.dll v4.5.6002.23731 and text is nothing but empty squares as if it tried to use a language not implemented on the system (asian or so).
The other has msi.dll v3.1.4001.5512 and display texts correctly, not so microscopic as mentioned in first post but indeed smaller than system-wide.
Both libraries are advertised as Unicode, both systems are English with Regional settings Romanian. However, the second has full support for RTL and East-Asian languages installed. No idea how things work here because, well, it's Micro$oft. Hopefully this information is helpful somehow.

@ Slada: For any messagebox type, after you select the sequence of buttons you want using the radiobuttons, click the button (on the same row) that you wish to make as default; it will appear selected and the code will take care of it all. ;)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
Posts: 2912
Joined: 17 Jul 2016, 01:02

Re: MagicBox Factory

05 Apr 2017, 06:49

This is very nice. It should be linked to in the documentation. :bravo:
I see the InputBoxEx example file and the function in the functions folder, but I don't see the option to generate code for such an inputbox in the factory.

User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

Re: MagicBox Factory

06 Apr 2017, 20:18

@Drugwash: Thanks for pointing that out.

@Helgef: InputBoxEx was a later addition and it will probably not be featured in the GUI.
User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

Re: MagicBox - Message Box Generator

10 Apr 2017, 08:39

Changes in version 1.0.2:
- Generated code can be directly copied from the main window.
- Fixed incorrect or unspecified data types in DllCalls and NumPuts.
- The name of the project is MagicBox only. The MagicBox function was renamed to MsgBoxEx.

:arrow: Download
Posts: 874
Joined: 19 Dec 2013, 11:16
Location: USA

Re: MagicBox - Message Box Generator

11 Apr 2017, 07:28

Suggestion: Allow user to export the current configuration, to be imported at a later time to make changes. XML Export?
User avatar
Posts: 2317
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: MagicBox - Message Box Generator

11 Apr 2017, 07:31

Or with JSON -> AutoHotkey-JSON (by coco)
btw Alguimist.. did you changed my suggestions via pm too? was also about Datatypes

Another tip for gui with different background-color than the normal one (see this example)
It removes the grey border around the button border
[AHK] x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

Re: MagicBox - Message Box Generator

11 Apr 2017, 08:44

@TheDewd: Some fields can be loaded from MagicBox.ini (must be created):

Code: [Select all] [Download] GeSHi © Codebox Plus

Text=Sample text

@jNizM: The data types were fixed in WinSpy as well, but I have yet to fix some minor bugs for a new release. For MagicBox I checked Windows Data Types for AHK.
Posts: 874
Joined: 19 Dec 2013, 11:16
Location: USA

Re: MagicBox - Message Box Generator

11 Apr 2017, 13:21


Thanks! I should have looked at your code. I just found the option to right-click on the "Question" icon to get a different style for TaskDialog and TaskDialogIndirect. It's like an easter egg to me ;)
Posts: 390
Joined: 22 Jan 2017, 19:37

Re: MagicBox - Message Box Generator

07 May 2017, 19:23

I really love this tool, Alquimist. Maybe you can help me with this problem I had with a timeout for TaskDialogIndirect.
The code generated directly from MagicBox 1.0.2 for my test (#Warn is on) is:

If I change

Code: [Select all] [Download] GeSHi © Codebox Plus

TDCallback(hWnd, Notification, wParam, lParam, RefData) {
CBData := Object(RefData)


Code: [Select all] [Download] GeSHi © Codebox Plus

TDCallback(hWnd, Notification, wParam, lParam, RefData) {
Global CBData := Object(RefData)

or if I change

Code: [Select all] [Download] GeSHi © Codebox Plus

TDCallback := RegisterCallback("TDCallback", "Fast")
CBData := {}
CBData.Timeout := 3000 ; ms


Code: [Select all] [Download] GeSHi © Codebox Plus

TDCallback := RegisterCallback("TDCallback", "Fast")
Global CBData := {}
CBData.Timeout := 3000 ; ms

it runs fine. I don't know enough about best practices to choose the best place to put "Global", but I'm pretty sure it needs to be in there somewhere, doesn't it? Of course it just throws a warning, not an error.
User avatar
Posts: 227
Joined: 05 Oct 2015, 16:41

Re: MagicBox - Message Box Generator

08 May 2017, 08:48

The warn can be avoided with:

Code: [Select all] [Download] GeSHi © Codebox Plus

Local CBData := Object(RefData)
Posts: 390
Joined: 22 Jan 2017, 19:37

Re: MagicBox - Message Box Generator

08 May 2017, 12:05

Thank you, Alguimist! I went at it backwards.
User avatar
Posts: 62
Joined: 25 Nov 2015, 09:01
Location: Germany

Re: MagicBox - Message Box Generator

17 Nov 2017, 08:57

Thanks a lot for this great tool, Alguimist... I love it... :angel:
I created a Project with a TaskDialogIndirect-box (compiled x86) which works as expected on my Windows10 x64-barebone, but on my Windows10 x86-notebook no defined icon has been displayed next to text and footer.
The box can be closed with no error... any idea ?
To err is human. :shh:
moefr01 :wave:
Last edited by moefr01 on 18 Nov 2017, 15:10, edited 1 time in total.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: stealzy and 10 guests