Using MessageBoxIndirect to show message boxes with custom icons

MessageBoxIndirect is a little known API function defined in user32.dll, that lets you customize message boxes just that little bit more (and it’s highly probable that MessageBox itself uses MessageBoxIndirect internally).

Here’s some sample code that shows how you can show a message box with a custom icon :-

MSGBOXPARAMS params = {0};
params.cbSize = sizeof MSGBOXPARAMS;
params.hInstance = hInstance;
params.lpszText = "Hello there";
params.lpszCaption = "Nish";
params.dwStyle = MB_OK | MB_USERICON;
params.dwLanguageId = MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL);
params.lpszIcon = MAKEINTRESOURCE(IDI_ICON1);
MessageBoxIndirect (&params);

See MSDN for full documentation on MessageBoxIndirect and MSGBOXPARAMS.

7 thoughts on “Using MessageBoxIndirect to show message boxes with custom icons

  1. Hey nish I have a doubt in C++. Actually my prof asked me to code a project in C++ in unix platform and in this I have to display a form and in that form I have to display and image. this image file is precomprssed using an algorithm, Now I have to open this precompressed image file using the decompression algorithm and display it at a corner on the screen or form that i have created.
    please help me out in this. I am confused

  2. to vaidehi:
    i suppose, the basic alorithm for solving your problem is to read that image from file, decompress, store it in memory, create dialog and pass pointer to that memory block where you store your image and in dialog show image.

  3. Why msgboxindirect not working when the dwLanguageId of MSGBOXPARAMS is changes to some other language? For example, is LANG_GERMAN in place of LANG_NEUTRAL is not replacing the Ok and Cancel in German viz., Ok and Abbrechen. Could you find out the cause of this?

    Thanks in anticipation,
    BalaChandra Sekhar M
    balachandram@ivycomptech.com

Leave a reply to Lior Cancel reply