A Wrapper for MessageBoxIndirect

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

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
  2.   #include "MessageBox.h"
      ....
    
      CMessageBox box;
      
    or
      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);
    
        box.SetLangID(MAKELANGID(LANG_CHINESE, 
         SUBLANG_CHINESE_TRADITIONAL));
        
  5. Call DoModal.
  6.     if(box.DoModal() == MB_OK)
        {
          // Do something here
        }
        else
        {
          // Do something else
        }
        

That's it!

Downloads

Download demo project - 16 Kb
Download source - 2 Kb


Comments

  • Very Nice

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

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

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds