CMessageBoxX v1.16 An MFC class to
encapsulate the MessageBox API
- Subclasses the message box window to allow additional customisation.
- Sub classed using a standard CWnd derived class, so you can use standard
MFC message maps in the class itself and any classes you derive from it.
- Implements standard support for automatic addition of icons just like in
MFC.
- Allows custom icons to be easily added to the message box.
- Implements timed out message box support with specific timeout button. The
timeout can also be reset based on mouse or keyboard activity.
- Implements disabled button support. Helpful where you want to implement
Nag screens when you want to remind an end user to register your product.
- Implements support for including checkboxes on the message box. For example
you can implement "Don't remind me again" type message boxes.
- Includes support for right aligned buttons instead of the default for the
MessageBox API on older versions of Windows which was to have the buttons centered.
- Integrates with MFC support for message box help context.
- Fully Unicode compliant.
- Optionally supports a hyperlink in your message box via the CMFCLinkCtrl
MFC class.
- Supports selectable text in your message boxes.
- Includes support for user defined animated text and captions
The enclosed zip file contains the CMessageBoxX
source code and a simple test program to exercise the class provided.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
Updates
v1.16 (20 February 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all variable
declarations
8 August 2021
- Updated copyright details.
- Updated compiler settings to more modern defaults.
v1.15 (12 April 2020)
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.14 (28 January 2020)
- Updated copyright details.
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.13 (18 December 2019)
- Fixed various Clang-Tidy static code analysis warnings in the code.
v1.12 (9 September 2019)
- Fixed a number of compiler warnings when the code is compiled with VS
2019 Preview
v1.11 (22 April 2019)
- Updated copyright details
- Updated the code to clean compile on VC 2019
v1.10 (16 September 2018)
- Fixed a number of compiler warnings when using VS 2017 15.8.4
v1.09 (1 July 2018)
- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
v1.08 (19 July 2016)
- Updated copyright details.
- Tidied up the implementations of GetFirstButton, GetRightMostButtonRect,
RightAlignButtons, CreateCheckBox, FixUpPositionsToSuitQHTM, ModifyButtonCaptions &
GetCheckBoxSize.
- Fixed a bug in the creation of the selectable text control in CMessageBoxX::OnInitDialog.
Thanks to Petr Stejskal for reporting this issue.
- Removed two calls to VERIFY in CMessageBoxX::OnInitDialog. Instead now failure
to create the selectable text control or the QHTM control results in the message
box failing with IDCANCEL.
- Added a BOOL return value to SetCaption, SetText & SetHTMLText methods
which internally call LoadString.
- Removed support for QHTM control from the code as it looks like the control
is no longer being developed and is not available from the author's web site
at http://gipsysoft.com
- Tested code operates correctly on High DPI monitors.
- Added SAL annotations to all the code.
- Added support for adding a hyperlink to the messagebox. Thanks to Petr Stejskal
for requesting this feature. Please note that you should not create a messagebox
which includes both a checkbox and a hyperlink as you will get the hyperlink
control appearing over the white / gray boundary on the message box which will
look ugly. If you really want a more complicated dialog which supports hyperlinks
and checkboxes at the same time then please check out the TaskDialog Windows
API or the author's own XTaskDialog code at
http://www.naughter.com/xtaskdialog.html
which provides an emulation of Task Dialogs on versions of Windows prior to
Vista.
- The selectable text control is now created with the WS_TABSTOP style thus
allowing the text to be tabbed into via the keyboard.
v1.07 (17 November 2015)
- Verified the code compiles cleanly on VC 2015.
- Updated the sample apps main icon.
- Updated copyright details.
v1.06 (18 May 2014)
- Updated copyright details.
- Updated the code to compile cleanly on VC 2012 and later. Further changes
were required to achieve this because MFC in Visual Studio 2012 has been reworked
to use the SDK style fusion wrappers rather than those in the now defunct afxcomctl32.h
header file.
- Updated the SetCaption method to operate where AfxGetApp() returns NULL.
- Updated the project settings to more modern default values.
v1.05 (11 July 2008)
- Updated copyright details.
- Updated sample app to clean compile on VC 2008
- Removed VC 6 style classwizard comments from the code.
- The code has now been updated to support VC 2005 or later only.
- Code now compiles cleanly using Code Analysis (/analyze)
- Code now uses newer C++ style casts instead of C style casts.
- Updated sample app to demonstrate support for user icons
- Class now correctly handles the manifest contexts which the MessageBox API's
can have when you are using Common Control v6 or later
v1.04 (11 August 2007)
- Updated copyright details.
- Check box text control is now clipped to the width of the main text control
if its calculated width will exceed the message box client area. This was done
following a report from Kyle Alons that this text can get clipped on Vista when
you pick a longish piece of text as the check box text. You should ensure you
pick a shortish piece of text to avoid this problem as well as test all your
message boxes on all the operating systems you will be supporting your application
on.
- Addition of a CMESSAGEBOXX_EXT_CLASS to allow the code to be more easily
added to an extension dll.
v1.03 (5 November 2006)
- Minor update to stdafx.h of sample app to avoid compiler warnings in VC
2005.
- Code now uses QHTM const for the class name
v1.02 (3 July 2006)
- Code now uses newer C++ style casts instead of C style casts.
- Class now allows you to put HTML text into the message box. This is provided
by the QHTM HTML control provided at
http://www.gipsysoft.com/qhtm/.
You may need to purchase a license (depending on the type of application you
are developing) as well as follow their instructions on deploying it if you
want this functionality with CMessageBoxX. This functionality by default is
not included in CMessageBoxX and is only available when you define the preprocessor
macro "CMESSAGEBOXX_HTML_SUPPORT".
- Implemented support for selectable text. This means that end-users can select
the text in the message box and paste it into the clipboard. Very helpful if
you want end-users to record the details of error messages etc in your apps.
- Button captions can now be modified via SetModifiedButtonCaption.
- Added user defined animated text support.
- Added user defined animated caption support.
- Updated code to clean compile on VC 2005.
v1.01 (24 April 2006)
- Updated copyright details.
- Updated documentation to use the same style as the web site.
- UpdateCaptionDueToTimer method has been renamed to UpdateUIDueToTimer
- Now includes support for including a check box on the MessageBox. To achieve
this simply call SetCheckBox with the text to show on the check box and its
initial checked state prior to calling DoModal to show the message box. Then
when DoModal returns simple call GetCheckBoxState to determine whether the check
box was ticked or not.
- Now includes support for right aligning buttons instead of the default for
the MessageBox API which is to have the buttons centered. The support for checkboxes
and right aligned buttons is inspired by the GSMessageBox article at
http://www.gipsysoft.com/messagebox/.
- Both SetTimeout and SetDisabledButton methods now include a "bModifyCaptionDuringCountdown"
which determines if they should cause the MessageBox caption to be modified
during their timer countdowns
- Updated the sample app to allow most of the functionality of the code to
be optionally tested.
- SetTimeout method now includes a bResetTimeoutOnUserActivity parameter.
- Addition of GetCurrentTimerCaption() and GetCurrentDisabledCaption() virtual
methods which allow the timeout and disabled captions to be easily customized
at runtime.
- Fixed a number of compiler warnings when the code is compiled using /Wp64
v1.0 (19 April 2003)