Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CPPMessageBox v1.0

0.00/5 (No votes)
14 Feb 2005 1  
Extended MessageBox class

Sample Image - CPPMessageBox.gif

Contents

Introduction

Another MessageBox :The CodeProject site contains more solutions as an extension to the standard MessageBox. So why another one? You may ask. I don't develop classes unless I feel there's a real need for them in my own projects. For a long time I've used "XMessageBox - A reverse-engineered MessageBox()" class by Hans Dietrich. That is a nice class and I am thankful to him for his work. However, all things comes an end. This class has ceased to satisfy me. I wished to have a class that would allow me to control the colors of the message text and background. I had already developed, and successfully tested, a class for drawing pseudo-HTML in my own classes CPPToolTip and CPPHtmlStatic. So, the solution for drawing colored text was easily found. For the additional features of this class, I relied on already available classes on CodeProject. Many thanks to all those who have helped me in creating this class, in particular to the authors of these classes published on CodeProject:

PPMessageBox

int PPMessageBox(
                HWND hwnd, 
                LPCTSTR lpszMessage,
                LPCTSTR lpszCaption = NULL, 
                DWORD dwStyle = MB_OK | MB_ICONEXCLAMATION,
                const PPMSGBOXPARAMS * pMsgBox = NULL
                );

Parameters

  • hWnd

    [in] Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

  • lpszText

    [in] Pointer to a null-terminated string that contains the message to be displayed.

  • lpszCaption

    [in] Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title Error is used.

  • dwStyle

    [in] Specifies the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.

To indicate the buttons displayed in the message box, specify one of the following values:

Value
Description
MB_ABORTRETRYIGNORE The message box contains three push buttons: Abort, Retry, and Ignore.
MB_CANCELTRYCONTINUE The message box contains three push buttons: Cancel, Try Again, Continue.
MB_CONTINUEABORT The message box contains two push buttons: Continue and Abort.
MB_HELP Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner.
MB_IGNOREIGNOREALLCANCEL The message box contains three push buttons: Ignore, Ignore All , Cancel.
MB_NOTOALL Adds a "Not to All" button to the message box. This flag combined with MB_YESNO, MB_YESNOCANCEL flags only.
MB_OK The message box contains one push button: OK . This is the default.
MB_OKCANCEL The message box contains two push buttons: OK and Cancel .
MB_RETRYCANCEL The message box contains two push buttons: Retry and Cancel .
MB_SKIPSKIPALLCANCEL The message box contains three push buttons: Skip, Skip All, and Cancel .
MB_YESNO The message box contains two push buttons: Yes and No .
MB_YESNOCANCEL The message box contains three push buttons: Yes , No , and Cancel .
MB_YESTOALL Adds a "Yes to All" button to the message box. This flag combined with MB_YESNO, MB_YESNOCANCEL flags only.

To indicate the checkbox displayed in the message box, specify one of the following values:

Value
Description
MB_CHECKBOX Adds a checkbox to the message box. If MB_CHECKBOXUNDERBUTTONS flag not specified, a checkbox will be placed over the message box buttons. A checkbox has a "Do Not Show Again" text by default. You can change this text through lpszCheckBoxText member of a PPMSGBOXPARAMS structure.
MB_CHECKBOXCHECKED A checkbox will check by default. This flag combined with MB_CHECKBOX only.
MB_CHECKBOXUNDERBUTTONS A checkbox will place under the message box buttons. This flag combined with MB_CHECKBOX only.

To display an icon in the message box, specify one of the following values.

Value
Description
MB_ICONEXCLAMATION An exclamation-point icon appears in the message box.
MB_ICONWARNING An exclamation-point icon appears in the message box.
MB_ICONINFORMATION An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONASTERISK An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONQUESTION A question-mark icon appears in the message box.
MB_ICONSTOP A stop-sign icon appears in the message box.
MB_ICONERROR A stop-sign icon appears in the message box.
MB_ICONHAND A stop-sign icon appears in the message box.

To indicate the default button, specify one of the following values.

Value
Description
MB_DEFBUTTON1 The first button is the default button.
MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, MB_DEFBUTTON4, MB_DEFBUTTON5, or MB_DEFBUTTON6 is specified.
MB_DEFBUTTON2 The second button is the default button.
MB_DEFBUTTON3 The third button is the default button.
MB_DEFBUTTON4 The fourth button is the default button.
MB_DEFBUTTON5 The fifth button is the default button.
MB_DEFBUTTON6 The sixth button is the default button.

To specify other options, use one or more of the following values:

Value
Description
MB_NORESOURCE Do not try to load button strings from resources. (See PPMessageBox.h for string resource id numbers.) If this flag is used, English strings will be used for buttons and checkboxes. If this flag is not used, PPMessageBox() will attempt to load the strings for buttons and checkboxes from string resources first, and then use English strings if that fails.
MB_NOSOUND Do not play sounds when message box is displayed.
MB_RIGHT The text is right-justified.
MB_SETFOREGROUND The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
MB_TOPMOST The message box is created with the WS_EX_TOPMOST window style.
  • pMsgBox

Pointer to a PPMSGBOXPARAMS structure that contains information used to display the message box.

Return values

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect. If there is no enough memory to create the message box, the return value is zero. If the function succeeds, the return value is one of the following menu-item values:

Value
Description
IDABORT Abort button was selected.
IDCANCEL Cancel button was selected.
IDCLOSE Close button was selected.
IDCONTINUE Continue button was selected.
IDCUSTOM1 Custom 1 button was selected.
IDCUSTOM2 Custom 2 button was selected.
IDCUSTOM3 Custom 3 button was selected.
IDCUSTOM4 Custom 4 button was selected.
IDIGNORE Ignore button was selected.
IDIGNOREALL Ignore All button was selected.
IDNO No button was selected.
IDNOTOALL No To All button was selected.
IDOK OK button was selected.
IDRETRY Retry button was selected.
IDSKIP Skip button was selected.
IDSKIPALL Skip All button was selected.
IDTRYAGAIN Try Again button was selected.
IDYES Yes button was selected.
IDYESTOALL Yes To All button was selected.

Return value can include a combination of the following flags:

Value
Description
MB_CHECKBOXCHECKED A checkbox was checked.
MB_TIMEOUT Returned if timeout expired.

Remarks

The PPMessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons.

When you use a system-modal message box to indicate that the system is low on memory, the strings pointed to by the lpszText and lpszCaption members of the PPMSGBOXPARAMS structure should not be taken from a resource file, because an attempt to load the resource may fail.

If you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter. The hWndparameter should not identify a child window, such as a control in a dialog box.

CPPMessageBox Overview | Class Members

PPMessageBoxIndirect

<CODE>int PPMessageBoxIndirect(
                const PPMSGBOXPARAMS * pMsgBox = NULL
                );

Parameters

  • pMsgBox

Pointer to a PPMSGBOXPARAMS structure that contains information used to display the message box.

Return values

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect. If there is no enough memory to create the message box, the return value is zero. If the function succeeds, the return value is one of the following menu-item values:

Value
Description
IDABORT Abort button was selected.
IDCANCEL Cancel button was selected.
IDCLOSE Close button was selected.
IDCONTINUE Continue button was selected.
IDCUSTOM1 Custom 1 button was selected.
IDCUSTOM2 Custom 2 button was selected.
IDCUSTOM3 Custom 3 button was selected.
IDCUSTOM4 Custom 4 button was selected.
IDIGNORE Ignore button was selected.
IDIGNOREALL Ignore All button was selected.
IDNO No button was selected.
IDNOTOALL No To All button was selected.
IDOK OK button was selected.
IDRETRY Retry button was selected.
IDSKIP Skip button was selected.
IDSKIPALL Skip All button was selected.
IDTRYAGAIN Try Again button was selected.
IDYES Yes button was selected.
IDYESTOALL Yes To All button was selected.

Return value can include a combination of the following flags:

Value
Description
MB_CHECKBOXCHECKED A checkbox was checked.
MB_TIMEOUT Returned if timeout expired.

Remarks

The PPMessageBoxIndirect function 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.

When you use a system-modal message box to indicate that the system is low on memory, the strings pointed to by the lpszText and lpszCaption members of the PPMSGBOXPARAMS structure should not be taken from a resource file, because an attempt to load the resource may fail.

If you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.

PPMSGBOXAREA_BK structure

The PPMSGBOXAREA_BK structure contains information used to display a message box. The PPMessageBox and PPMesssageBoxIndirect functions uses this structure.

typedef struct PPMSGBOXAREA_BK
{
    int nSepType;
    int nSepAlign;
    LPCTSTR lpszSepText;
    int nEffectBk;
    COLORREF crStartBk;
    COLORREF crMidBk;
    COLORREF crEndBk;
} PPMSGBOXAREA_BK;

Members

  • nSepType

A type of the area separator. Specify one of the following values:

Value
Description
PPMSGBOX_SEP_NONE A separator was not specified. This a default value.
PPMSGBOX_SEP_ETCHED A separator is an etched horizontal line.
PPMSGBOX_SEP_BLACK A separator is a black horizontal line.
PPMSGBOX_SEP_WHITE A separator is a white horizontal line.
  • lpszSepText

Pointer to a null-terminated string, or the identifier of a string resource, that contains the separator text. If this member is NULL, the separator text isn't used.

  • nSepAlign

An alignment of the separator text. Specify one of the following values:

Value
Description
PPMSGBOX_ALIGN_LEFT A text displayed to the left of the message box. This a default value.
PPMSGBOX_ALIGN_RIGHT A text displayed to the right of the message box.
PPMSGBOX_ALIGN_CENTER A text displayed to the center of the message box.
  • nEffectBk

The effect to fill the message box background. Specify one of the following values:

Value
Description
-1 Transparent. An area with no filling. The default value.
CPPDrawManager::EFFECT_SOLID A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HGRADIENT A horizontal gradient filling. Uses a crStartBk and crEndBk color values.
CPPDrawManager::EFFECT_VGRADIENT A vertical gradient filling. Uses a crStartBk and crEndBk color values.
CPPDrawManager::EFFECT_HCGRADIENT A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_VCGRADIENT A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_3HGRADIENT A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_3VGRADIENT A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_NOISE A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_DIAGSHADE A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HSHADE A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_VSHADE A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HBUMP A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_VBUMP A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_SOFTBUMP A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HARDBUMP A solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_METAL A solid filling. Uses a crStartBk color value.

PPMSGBOXPARAMS structure

The PPMSGBOXPARAMS structure contains information used to display a message box. The PPMessageBox and PPMesssageBoxIndirect functions uses this structure.

typedef struct PPMSGBOXPARAMS
{
  //MessageBox area

  HWND hParentWnd;
  HINSTANCE hInstanceStrings;
  HINSTANCE hInstanceIcons;
  LPCTSTR lpszCaption;
  LPCTSTR lpszModuleName;
  LPCTSTR lpszCompanyName;
  int nLine;
  DWORD dwReportMsgID;
  PPMSGBOXAREA_BK pMsgBoxBk;
 
  //Header area

  int nHeaderHeight;
  LPCTSTR lpszHeaderText;
  PPMSGBOXAREA_BK pHeaderBk;
 
  //Message area

  LPCTSTR lpszText;
 
  //Control area

  int nControlsAlign;
  DWORD dwStyle;
  PPMSGBOXAREA_BK pControlBk;
 
  //MoreInfo area

  LPCTSTR lpszMoreInfo;
  PPMSGBOXAREA_BK pMoreInfoBk;
 
  int nTimeoutSeconds;
  int nDisabledSeconds;
  BOOL bDisableAllCtrls;
  DWORD dwContextHelpID;
  DWORD dwUserIconID;
  LPCTSTR lpszCustomButtons;
  LPCTSTR lpszCheckBoxText;

  mapLocalBtnText * pLocalBtnText;
} PPMSGBOXPARAMS;

Members

  • hParentWnd

    Handle to the owner window. This member can be NULL.

  • hInstanceString

    Handle to the module that contains the string resource identified by the lpszText, lpszCaption and other string members.

  • hInstanceIcons

    Handle to the module that contains the icon resource identified by the lpszIcon member.

  • lpszCaption

    Pointer to a null-terminated string, that contains the message box title. If this member is NULL, the default title Error is used.

  • lpszModuleName

    Specifies the source module name for the application. This may be the actual source module name (for example, the name returned by the __FILE__ macro) or a name meaningful to the context (for example, "ConfirmFileDelete"). This is used when saving the "Do Not Ask/Tell" checkbox state in the registry or ini file.

    It is up to the application to manage this registry entry. If it is necessary to clear out this entry each time the application starts up, the application must include the code to do this. All key/value pairs for XMessageBox are stored in the registry under HKEY_CURRENT_USER\Software\CompanyName\AppName\PPMessageBox. If an ini file is being used, the checkbox state will be saved in the file PPMessageBox.ini, in the app's directory.

    When the message box is displayed, if lpszModule has been specified in the XMSGBOXPARAMS struct, the message box will only be displayed if the registry entry does not exist. If the message box is displayed, and the user checks the "Do Not Ask/Tell" checkbox, the checkbox state will be saved in the registry.

  • lpszCompanyName

    Specifies the company name for the application. This is used when saving the "Do Not Ask/Tell" checkbox state in the registry or ini file.

  • nLine

    Specifies the source module line number for the application. This is used when saving the "Do Not Ask/Tell" checkbox state in registry. Note that regardless of whether the lpszModule string is encoded, the line number will not be encoded.

  • dwReportMsgID

    Specifies the message to be sent by click on the Report button.

  • pMsgBoxBk

    PPMSGBOXAREA_BK structure that contains information used to display the background of the all message box.

  • nHeaderHeight

    The minimal height of the message box header.

  • lpszHeaderText

    Pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro, that contains the header to be displayed. This string may has a HTML-like format.

  • pHeaderBk

    PPMSGBOXAREA_BK structure that contains information used to display the background of the header area of the message box.

  • lpszText

    Pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro, that contains the message to be displayed. This string may be in a HTML-like format.

  • nControlsAlign

    Value that specifies the horizontal alignment of the button in the message box. This member can be one of the following values: PPMSGBOX_ALIGN_LEFT, PPMSGBOX_ALIGN_RIGHT or PPMSGBOX_ALIGN_CENTER.

  • dwStyle

    Specifies the contents and behavior of the dialog box. This member can be a combination of flags described for the dwStyle parameter of the PPMessageBox function.

    In addition, you can specify the MB_USERICON flag if you want the message box to display the icon specified by the lpszIcon member.

  • pControlBk

    PPMSGBOXAREA_BK structure that contains information used to display the background of the controls' area of the message box.

  • lpszMoreInfo

    Pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro, that contains the additional information to be displayed. This string may be in a HTML-like format.

  • pMoreInfoBk

    PPMSGBOXAREA_BK structure that contains information used to display the background of the MoreInfo area of the message box.

  • nTimeoutSeconds

    Specifies the time-out value, in seconds, before auto-click a default button.

  • nDisabledSeconds

    Specifies the time-out value, in seconds, to disable a default button or all buttons of the message box (exclude the 'Help', 'Report' and 'MoreInfo' buttons).

  • bDisableAllCtrls

    Flag that indicates whether default button is being disabled (FALSE) or all buttons of the message box are being disabled (TRUE). The 'Help', 'Report' and 'MoreInfo' buttons are never disabled.

  • dwContextHelpID

    Identifies a help context. If a help event occurs, this value is specified in the HELPINFO structure that the message box sends to the owner window or callback function.

  • lpszIcon

    Identifies an icon resource. This parameter can be either a null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro.

    To load one of the standard system-defined icons, set the hInstance member to NULL and zIcon to one of the values listed with the LoadIcon function.

    This member is ignored if the dwStyle member does not specify the MBUSERICON flag.

  • lpszCustomButtons

    Pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro, that contains the list of the custom button captions. This string has the format "Custom 1\nCustom 2\nCustom 3\nCustom 4". NULL if custom buttons are not used.

    Up to four buttons may be specified. When a custom button is clicked, it will return the value IDCUSTOM1, IDCUSTOM2, etc. When custom buttons are specified, no other buttons will be displayed (except 'Help', 'Report' and 'MoreInfo' buttons. These buttons may be displayed anyway).

  • lpszCheckBoxText

    Pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro, that contains the checkbox caption. You can change a checkbox caption for each message box. If this parameter is NULL, then a checkbox caption is retrieved from the map specified by pLocalBtnText member or from the resources. If that parameter is also NULL, the check box caption will default to 'Do not show again'.

  • pLocalBtnText

    Pointer to the map that contains pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro that contains the button captions. Key of the map is the button ID (for example: IDOK, IDCANCEL, IDYES, MB_CHECKBOX etc.).

CPPMessageBox class

The CPPMessageBox class is a MFC wrapper around API PPMessageBox and PPMessageBoxIndirect methods. This class is intended for easy work with big and difficult PPMSGBOXPARAMS structure of messagebox customization. For this purpose it contains a set of methods:

MessageBox Displays a message box.
MessageBoxIndirect Displays a message box.
GetMessageBoxParams Receives the information used to display the message box.
SetMessageBoxParams Sets the information used to display the message box.
SetTimeouts Set a time-out value to auto-click or to disable the buttons of the message box
SetCustomButtons Specifies the strings to be used for the custom button captions.
SetBackground Sets an effect to fill a background of the message box area.
SetSeparator Sets the separator of the message box area.
ClearAllButtonsText Clear all buttons text.
SetButtonText Sets the text to the specified button.
GetButtonText Receives the text to the specified button.

CPPMessageBox::MessageBox

int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption = NULL, 
          UINT nStyle = MB_OK | MB_ICONEXCLAMATION, 
          const PPMSGBOXPARAMS * pMsgBox = NULL);

Parameters

  • lpszText - Pointer to a null-terminated string that contains the message to be displayed.
  • lpszCaption - Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title Error is used.
  • nStyle - Specifies the contents and behavior of the dialog box. See the PPMessageBox method for more information.
  • pMsgBox - Pointer to a PPMSGBOXPARAMS structure that contains information used to display the message box.

Return values

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

If the function succeeds, see the PPMessageBox method for more information about return values.

If there is not enough memory to create the message box, the return value is zero.

Remarks

The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons. See the PPMessageBox method for more information.

CPPMessageBox Overview

CPPMessageBox::MessageBoxIndirect

int MessageBoxIndirect(const PPMSGBOXPARAMS * pMsgBox = NULL);

Parameters

  • pMsgBox - Pointer to a PPMSGBOXPARAMS structure that contains information used to display the message box.

Return values

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect. If the function succeeds, see the PPMessageBox method for more information about return values. If there is not enough memory to create the message box, the return value is zero.

Remarks

The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons. See the PPMessageBoxIndirect method for more information.

CPPMessageBox Overview

CPPMessageBox::GetMessageBoxParams

PPMSGBOXPARAMS * GetMessageBoxParams();

Return value

  • pMsgBoxParams - Pointer to a PPMSGBOXPARAMS structure that receives the information used to display the message box.

Remarks

This method receives the information used to display the message box.

CPPMessageBox Overview

CPPMessageBox::SetMessageBoxParams

void SetMessageBoxParams(const PPMSGBOXPARAMS * pMsgBoxParams);

Parameters

  • pMsgBoxParams - Pointer to a PPMSGBOXPARAMS structure that contains the information used to display the message box.

Remarks

Sets the information used to display the message box.

CPPMessageBox Overview

CPPMessageBox::SetTimeouts

void SetTimeouts(int nAutoclick, int nDisable = 0, BOOL bGlobalDisable = FALSE);

Parameters

  • nAutoclick - Specifies the time-out value to auto click a default button, in seconds. If this parameter is a non-zero value then a default button will be clicked after time-out (nDisable and bGlobalDisable parameters are ignored).
  • nDisable - Specifies the time-out value to disable a default button or to disable all buttons of the message box, in seconds. This parameter is valid only if nAutoclick parameter is zero.
  • bGlobalDisable - TRUE to disable all buttons of the message box; otherwise to disable a default button only.

Remarks

Set a time-out value to auto-click or to disable the buttons of the message box. For more information see a following table:

Parameters
Action
nAutoclick
nDisable
bGlobalDisable
0 0 FALSE No any time-outs
Time-out value to auto click a default button x x Auto click a default button
0 Time-out value to disable a default button FALSE Disable a default button
0 Time-out value to disable all buttons TRUE Disable all buttons

CPPMessageBox Overview

CPPMessageBox::SetCustomButtons

void SetCustomButtons(LPCTSTR lpszButtonNames = NULL);

Parameters

  • lpszButtonNames - Pointer to a null-terminated string, or the identifier of a string resource passed to the MAKEINTRESOURCE macro, that contains the list of the custom button captions.

Remarks

Specifies the strings to be used for the custom button captions. This string has the format "Custom 1\nCustom 2\nCustom 3\nCustom 4". NULL if custom buttons are not used. Up to four buttons may be specified. When a custom button is clicked, it will return the value IDCUSTOM1, IDCUSTOM2, etc. When custom buttons are specified, no other buttons will be displayed (except 'Help', 'Report' and 'MoreInfo' buttons. These buttons can always be displayed).

CPPMessageBox Overview

CPPMessageBox::SetBackground

void SetBackground(DWORD dwArea, PPMSGBOXAREA_BK * pAreaBk);
void SetBackground(DWORD dwArea, int nEffectBk = -1, COLORREF crStartBk = -1, 
                     COLORREF crEndBk = -1, COLORREF crMidBk = -1);

Parameters

  • dwArea - The area of the message box to fill background. Specify one of the following values: PPMSGBOX_HEADER_AREA, PPMSGBOX_MESSAGE_AREA, PPMSGBOX_CONTROL_AREA, PPMSGBOX_MOREINFO_AREA.
  • pAreaBk - Pointer to the PPMSGBOXAREA_BK structure that contains information used to fill the message box area. NULL if the area not filled.
  • nEffectBk - The effect to fill the area background of the message box. -1 if the area not filled.
  • crStartBk, crEndBk, crMidBk - The COLORREF value to fill background. -1 to COLOR_3DFACE.

Remarks

This method sets an effect to fill a background of the message box area.

CPPMessageBox Overview

CPPMessageBox::SetSeparator

void SetSeparator(DWORD dwArea, int nSepType = PPMSGBOX_SEP_NONE, 
     int nSepAlign = PPMSGBOX_ALIGN_LEFT, LPCTSTR lpszSepText = NULL);

Parameters

  • dwArea - The area of the message box to fill background, specify one of the following values: PPMSGBOX_HEADER_AREA, PPMSGBOX_CONTROL_AREA, PPMSGBOX_MOREINFO_AREA.
  • nSepType - The type of the separator, specify one of the following values: PPMSGBOX_SEP_NONE, PPMSGBOX_SEP_ETCHED, PPMSGBOX_SEP_BLACK, PPMSGBOX_SEP_WHITE.
  • nSepAlign - The alignment of the separator text, specify one of the following values: PPMSGBOX_ALIGN_LEFT, PPMSGBOX_ALIGN_RIGHT, PPMSGBOX_ALIGN_CENTER.
  • lpszSepText - Pointer to a null-terminated string, or the identifier of a string resource, that contains the separator text. If this member is NULL, the separator text isn't used.

Remarks

This method draws the separator of the message box area. See a PPMSGBOXAREA_BK structure to more information.

CPPMessageBox Overview

CPPMessageBox::ClearAllButtonsText

void ClearAllButtonsText(); 

Remarks

This method clears all button text.

CPPMessageBox Overview

CPPMessageBox::SetButtonText

void SetButtonText(DWORD dwBtnID, LPCTSTR lpszText = NULL);

Parameters

  • dwBtnID - The button identifier. Specify one of the following values:
    Value
    Description
    IDABORT Abort button.
    IDCANCEL Cancel button.
    IDCLOSE Close button.
    IDCONTINUE Continue button.
    IDIGNORE Ignore button.
    IDIGNOREALL Ignore All button.
    IDNO No button.
    IDNOTOALL No To All button.
    IDOK OK button.
    IDRETRY Retry button.
    IDSKIP Skip button.
    IDSKIPALL Skip All button.
    IDTRYAGAIN Try Again button.
    IDYES Yes button.
    IDYESTOALL Yes To All button.
    MB_CHECKBOX Check box button.
  • lpszText - Pointer to a null-terminated string, or the identifier of a string resource that contains the text for specified button. If this member is NULL, the default text is used.

Remarks

This method sets the text to the specified button. If a button doesn't hold text, then text will be loaded from resources or default text will be used.

CPPMessageBox Overview

CPPMessageBox::GetButtonText

LPCTSTR GetButtonText(DWORD dwBtnID);

Parameters

  • dwBtnID - The button identifier. See a SetButtonText method for the list of the available values.

Return value

Pointer to a null-terminated string, that contains the text for specified button. NULL if text for specified button isn't available.

Remarks

This method receives the text to the specified button.

CPPMessageBox Overview

How to Use?

To integrate PPMessageBox in your application you should add the following files to your project:

  • PPMessageBox.h
  • PPMessageBox.cpp
  • PPHtmlDrawer.h
  • PPHtmlDrawer.cpp
  • PPDrawManager.h
  • PPDrawManager.cpp
  • CeXDib.h, CeXDib.cpp - thanks to Davide Pizzolato and Davide Calabro. This class is used for extended background effects.
  • PPMessageBoxClass.h, PPMessageBoxClass.cpp - a wrapper class around PPMessageBox and PPMessageBoxIndirect API methods for use in MFC or WTL applications.

Use API method

Include the header file PPMessageBox.h in the header file where you want to call PPMessageBox() method.

Use as MFC class or WTL class

Include the header file PPMessageBoxClass.h in the header file where you want to use a CPPMessageBox() class and create an member variable.

CPPMessageBox m_pMsgBox;

You can use the OnCreate(),OnInitDialog() and any other methods for customization or showing message box.

History

  • 14 February 2005

    First release

Copyright & Disclaimer

THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO RESPONSIBILITIES FOR POSSIBLE DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS. IF YOU WISH TO THANK MY WORK, YOU MAY DONATE ANY SUM OF MONEY TO ME FOR SUPPORT OF DEVELOPMENT OF THIS CLASS. IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU ARE GENTLY ASKED TO DONATE ANY SUM OF MONEY TO THE AUTHOR.

Contacting the Author

You are encouraged to use this class everywhere you want; there is no fee required for CPPMessageBox. Freely add modifications and/or fix bugs, but please, send any of these to me!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here