Preface
Yes, another "Custom MsgBox" function.
This function was inspired by all the "Custom MsgBox" scripts that were shared via the
AutoHotkey forum. Many of the ideas and some code was extracted from posts written by
Icarus and
Roland.
See the References section for more information. Thanks to everyone who contributed.
Introduction
When you need a general-purpose dialog window, the
MsgBox command will usually do the job. If you don't like the default button names you can add a timer and a few
ControlSetText commands to change the standard MsgBox button labels to whatever you want.
On occasion, the standard
MsgBox dialog just doesn't cut it. You want a custom icon, different font, more buttons, etc., etc. In these cases, most developers (including myself) either do without or they create a custom GUI to do the job.
A function that creates a general-purpose dialog window has always been attractive to me. For the most part, I want something that looks and feels like the standard
MsgBox dialog but I also want something that can be customized on the fly. I created the
CMsgBox function to meet these requirements.
CMsgBox
A few of the key features include the following:
- Default driven. All of the function parameters are optional. Some of the parameters are assigned default values if the developer does not assign a value, others are appended to a default initial value.
- Icons. The function can display standard Msgbox icons ("User32.dll") or a custom icon. A custom icon can derived from the function default (usually "Shell32.dll"), the program's icon (if the script is compiled), or from the IconFile option.
- Sounds. If the Sound option is enabled, the function can play standard MsgBox sounds or a custom sound file (SoundFile option).
- Buttons position. Buttons can be left-justified, right-justified, or centered (default).
- GroupBox option. If enabled, the GroupBox option draws a rectangular frame around the icon and message text controls.
- Checkbox option. If enabled, the Checkbox option adds one or more checkboxes to the bottom left corner of the window. A common use for this option is to add a "Don't ask me again" checkbox.
- Radio option. Same as the Checkbox option except radio buttons are used instead checkboxes.
All of the features, options, and default/initial values have been documented in the script.
Screenshots



The CodeThe pertinent files are as follows:
The example script allows you toggle many of the function's options so that you can see how these options affect the
CMsgBox window.
Issues/Considerations/Bugs- Preview release. Since this a preview release of the function, some of the code has not been optimized and there may be some residual debug code lying around. If there is any interest, these issues will be corrected in future releases.
- Future stuff. The source may include documentation and/or code for (possible) future options (marked as "[Future]"). These options are either 1) not coded, 2) not working, or 3) have not been fully tested. Please do not use.
- Functions. This script calls several other functions. For testing and evaluation purposes, the source for these functions has been included in the primary script. In future releases, some of these functions will be moved to separate modules.
Customizing
As I mentioned earlier, this function is default-driven by design. Some of the defaults are system or logical defaults but many represent my personal preferences. Yes, you can override the defaults by providing the appropriate parameter value but it probably makes more sense to change some of the default values to reflect your requirements.
Most (all?) of the default values are represented by static variables at the top of the function. Every variable should include a description to give you an idea what/how the default is used. Go crazy!
References
The following are forum posts that I used to research this mini-project. Thank you for your contribution.
A handy dialogue technique! (and colorful msgbox's ^_^)
http://www.autohotkey.com/forum/topic10248.html
A handy dialogue technique! (and colorful msgbox's ^_^)
{Reply}
http://www.autohotkey.com/forum/viewtopic.php?p=63485#63485
Custom Buttons for MsgBox?
{Reply}
http://www.autohotkey.com/forum/viewtopic.php?p=98701#98701
[Function] Custom Msgbox / Custom Buttons
http://www.autohotkey.com/forum/viewtopic.php?t=32367
Final Thoughts
I hope that someone finds this useful.
---------------------------------------------------------------------------
v0.1 (Preview):
Original release.