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

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

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