Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / WTL
Article

CPPMessageBox v1.0

Rate me:
Please Sign up or sign in to vote.
4.89/5 (53 votes)
14 Feb 2005CPOL22 min read 173.2K   5.2K   128   56
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
                );</CODE>

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_CONTINUEABORTThe 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_IGNOREIGNOREALLCANCELThe message box contains three push buttons: Ignore, Ignore All , Cancel.
MB_NOTOALLAdds 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_SKIPSKIPALLCANCELThe 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_YESTOALLAdds 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_CHECKBOXAdds 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_CHECKBOXCHECKEDA checkbox will check by default. This flag combined with MB_CHECKBOX only.
MB_CHECKBOXUNDERBUTTONSA 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_ICONEXCLAMATIONAn exclamation-point icon appears in the message box.
MB_ICONWARNINGAn 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_ICONASTERISKAn icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONQUESTIONA question-mark icon appears in the message box.
MB_ICONSTOPA stop-sign icon appears in the message box.
MB_ICONERRORA stop-sign icon appears in the message box.
MB_ICONHANDA stop-sign icon appears in the message box.

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

Value
Description
MB_DEFBUTTON1The 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_DEFBUTTON2The second button is the default button.
MB_DEFBUTTON3The third button is the default button.
MB_DEFBUTTON4The fourth button is the default button.
MB_DEFBUTTON5The fifth button is the default button.
MB_DEFBUTTON6The sixth button is the default button.

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

Value
Description
MB_NORESOURCEDo 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_NOSOUNDDo not play sounds when message box is displayed.
MB_RIGHTThe text is right-justified.
MB_SETFOREGROUNDThe message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
MB_TOPMOSTThe 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
IDABORTAbort button was selected.
IDCANCELCancel button was selected.
IDCLOSEClose button was selected.
IDCONTINUE Continue button was selected.
IDCUSTOM1 Custom 1 button was selected.
IDCUSTOM2Custom 2 button was selected.
IDCUSTOM3Custom 3 button was selected.
IDCUSTOM4Custom 4 button was selected.
IDIGNOREIgnore button was selected.
IDIGNOREALLIgnore All button was selected.
IDNONo button was selected.
IDNOTOALLNo To All button was selected.
IDOKOK button was selected.
IDRETRYRetry button was selected.
IDSKIPSkip button was selected.
IDSKIPALLSkip All button was selected.
IDTRYAGAINTry Again button was selected.
IDYESYes button was selected.
IDYESTOALLYes To All button was selected.

Return value can include a combination of the following flags:

Value
Description
MB_CHECKBOXCHECKEDA checkbox was checked.
MB_TIMEOUTReturned 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
                );</CODE>

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
IDABORTAbort button was selected.
IDCANCELCancel button was selected.
IDCLOSEClose button was selected.
IDCONTINUE Continue button was selected.
IDCUSTOM1 Custom 1 button was selected.
IDCUSTOM2Custom 2 button was selected.
IDCUSTOM3Custom 3 button was selected.
IDCUSTOM4Custom 4 button was selected.
IDIGNOREIgnore button was selected.
IDIGNOREALLIgnore All button was selected.
IDNONo button was selected.
IDNOTOALLNo To All button was selected.
IDOKOK button was selected.
IDRETRYRetry button was selected.
IDSKIPSkip button was selected.
IDSKIPALLSkip All button was selected.
IDTRYAGAINTry Again button was selected.
IDYESYes button was selected.
IDYESTOALLYes To All button was selected.

Return value can include a combination of the following flags:

Value
Description
MB_CHECKBOXCHECKEDA checkbox was checked.
MB_TIMEOUTReturned 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_NONEA separator was not specified. This a default value.
PPMSGBOX_SEP_ETCHEDA separator is an etched horizontal line.
PPMSGBOX_SEP_BLACKA separator is a black horizontal line.
PPMSGBOX_SEP_WHITEA 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_LEFTA text displayed to the left of the message box. This a default value.
PPMSGBOX_ALIGN_RIGHTA text displayed to the right of the message box.
PPMSGBOX_ALIGN_CENTERA 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_SOLIDA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HGRADIENTA horizontal gradient filling. Uses a crStartBk and crEndBk color values.
CPPDrawManager::EFFECT_VGRADIENTA vertical gradient filling. Uses a crStartBk and crEndBk color values.
CPPDrawManager::EFFECT_HCGRADIENTA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_VCGRADIENTA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_3HGRADIENTA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_3VGRADIENTA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_NOISEA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_DIAGSHADEA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HSHADEA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_VSHADEA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HBUMPA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_VBUMPA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_SOFTBUMPA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_HARDBUMPA solid filling. Uses a crStartBk color value.
CPPDrawManager::EFFECT_METALA 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:

MessageBoxDisplays a message box.
MessageBoxIndirectDisplays a message box.
GetMessageBoxParamsReceives the information used to display the message box.
SetMessageBoxParamsSets the information used to display the message box.
SetTimeoutsSet a time-out value to auto-click or to disable the buttons of the message box
SetCustomButtonsSpecifies the strings to be used for the custom button captions.
SetBackgroundSets an effect to fill a background of the message box area.
SetSeparatorSets the separator of the message box area.
ClearAllButtonsTextClear all buttons text.
SetButtonTextSets the text to the specified button.
GetButtonTextReceives 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
00FALSENo any time-outs
Time-out value to auto click a default button xxAuto click a default button
0Time-out value to disable a default button FALSEDisable a default button
0Time-out value to disable all buttonsTRUEDisable 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
    IDABORTAbort button.
    IDCANCELCancel button.
    IDCLOSEClose button.
    IDCONTINUE Continue button.
    IDIGNOREIgnore button.
    IDIGNOREALLIgnore All button.
    IDNONo button.
    IDNOTOALLNo To All button.
    IDOKOK button.
    IDRETRYRetry button.
    IDSKIPSkip button.
    IDSKIPALLSkip All button.
    IDTRYAGAINTry Again button.
    IDYESYes button.
    IDYESTOALLYes 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer SvyazInvest
Belarus Belarus
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionIs it possible to copy the string into the clipboard with Ctrl+c ? Pin
zmau25-Dec-11 0:44
zmau25-Dec-11 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.