65.9K
CodeProject is changing. Read more.
Home

A Wrapper for MessageBoxIndirect

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.79/5 (7 votes)

Feb 23, 2000

viewsIcon

61431

downloadIcon

1736

A class which encapsulates MessageBoxIndirect.

  • Download demo project - 16 Kb
  • Download source files - 2 Kb
  • Sample Image - messagebox.gif

    Introduction

    Sometimes you might wish you could use other icons in a message box apart from the ones Windows gives you, or you might want to have more control over how your message box, specify which language to use, etc. Well, there is a way to do all this using the little-known API call MessageBoxIndirect.

    Here is a class which encapsulates MessageBoxIndirect (actually, it inherits from the MESSAGEBOXPARAMS structure which you pass to MessageBoxIndirect). You can use it like an MFC CDialog, although there are no dependencies on MFC.


    Usage

    1. Declare a CMessageBox object.
    #include "MessageBox.h"
    ....
    
    CMessageBox box;
    

    or

    CMessageBox box(hWnd, "My Text", "My Caption", MB_OK);
    

    2. Initialize it (If you are just displaying a standard Message Box you can skip this step

    box.SetIcon(IDI_SOMEICON);
    box.SetLangID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL));
    

    3. Call DoModal.

    if(box.DoModal() == MB_OK)
    {
    	// Do something here
    }
    else
    {
    	// Do something else
    }
    


    That's it!