A Wrapper for MessageBoxIndirect

Environment: Windows NT4 SP5, Visual C++ 6 SP2


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.


  1. Declare a CMessageBox object
  2.   #include "MessageBox.h"
      CMessageBox box;
      CMessageBox box(hWnd, "My Text", "My Caption", MB_OK);
  3. Initialize it (If you are just displaying a standard Message Box you can skip this step
  4.     box.SetIcon(IDI_SOMEICON);
  5. Call DoModal.
  6.     if(box.DoModal() == MB_OK)
          // Do something here
          // Do something else

That's it!


Download demo project - 16 Kb
Download source - 2 Kb


  • Very Nice

    Posted by jeffrey@toad.net on 10/11/2005 09:26am

    Hi Peter, Just what the doctor ordered... Jeff

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there's simply not enough quality talent to go around. In response, companies often resort to inferior solutions -- hiring substandard developers and engineers, recruiting talent on a part-time or temporary basis, poaching people from competitors, or burdening an already stressed IT staff for more of their labor. Fortunately, there's a better solution. Read this white paper to learn the business value of …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date