A Wrapper for MessageBoxIndirect | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 24, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.