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

  • Power and Automation Equipment makers face constrained CAPEX, equipment interoperability issues, and process inefficiencies. However, they can take advantage of secure Internet of Things (IoT) intelligent devices and systems to make better business decisions around asset utilization and performance, while simultaneously optimizing equipment interoperability and services efficiency. Watch this brief video to see how you can unlock the full potential of your assets and value chain.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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