Page 1 of 2

MagicBox - Message Box Generator

Posted: 31 Jul 2016, 17:47
by Alguimist
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 or higher, Unicode, 32 or 64-bit. Tested on Windows XP, 7 and 10.

Re: MagicBox Factory

Posted: 31 Jul 2016, 22:57
by hunter99
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.

Re: MagicBox Factory

Posted: 03 Aug 2016, 14:38
by vasili111
Good tool :) Thank you

Re: MagicBox Factory

Posted: 13 Sep 2016, 15:44
by Rami
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?

Re: MagicBox Factory

Posted: 15 Sep 2016, 06:36
by Alguimist
It's something that has not been implemented. Not a bug.

Re: MagicBox Factory

Posted: 25 Sep 2016, 03:22
by Tomer
Thanks Alguimist, great tool as always from you!

Re: MagicBox Factory

Posted: 22 Oct 2016, 13:30
by Alguimist
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

Re: MagicBox Factory

Posted: 21 Nov 2016, 18:12
by Slada

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

Suggestion, can you add default selected button in msgbox?

Re: MagicBox Factory

Posted: 22 Nov 2016, 13:03
by Drugwash
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. ;)

Re: MagicBox Factory

Posted: 05 Apr 2017, 06:49
by Helgef
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.


Re: MagicBox Factory

Posted: 06 Apr 2017, 20:18
by Alguimist
@Drugwash: Thanks for pointing that out.

@Helgef: InputBoxEx was a later addition and it will probably not be featured in the GUI.

Re: MagicBox - Message Box Generator

Posted: 10 Apr 2017, 08:39
by Alguimist
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

Re: MagicBox - Message Box Generator

Posted: 11 Apr 2017, 07:28
by TheDewd
Suggestion: Allow user to export the current configuration, to be imported at a later time to make changes. XML Export?

Re: MagicBox - Message Box Generator

Posted: 11 Apr 2017, 07:31
by jNizM
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

Re: MagicBox - Message Box Generator

Posted: 11 Apr 2017, 08:44
by Alguimist
@TheDewd: Some fields can be loaded from MagicBox.ini (must be created):

Code: Select all

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.

Re: MagicBox - Message Box Generator

Posted: 11 Apr 2017, 13:21
by TheDewd

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 ;)

Re: MagicBox - Message Box Generator

Posted: 07 May 2017, 19:23
by burque505
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

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

Code: Select all

TDCallback(hWnd, Notification, wParam, lParam, RefData) {
    Global CBData := Object(RefData)
or if I change

Code: Select all

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

Code: Select all

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.

Re: MagicBox - Message Box Generator

Posted: 08 May 2017, 08:48
by Alguimist
The warn can be avoided with:

Code: Select all

Local CBData := Object(RefData)

Re: MagicBox - Message Box Generator

Posted: 08 May 2017, 12:05
by burque505
Thank you, Alguimist! I went at it backwards.

Re: MagicBox - Message Box Generator

Posted: 17 Nov 2017, 08:57
by moefr01
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: