Search code examples
c++winapimessagebox

MessageBox has 2 different styles in C++? (Windows)


Not too long ago I found that there are 2 different styles/looks for the standard Windows Message Box. The interesting thing is, even having the exact same program/code for the message box, you might get either style 1 or style 2.

Message Box Style 1 Message Box Style 2

As you can clearly see, there are some differences in the style, but the code behind them is the exact same:

#include <Windows.h>

// inside DllMain
MessageBoxA(0, "MessageBoxA", "Message Box Style ...", MB_ICONINFORMATION);

I am sure you are wondering how I got two different results/styles with the same code? I made a very basic DLL which shows a message box right after being loaded/injected in a process. In most cases if you load the DLL in a console application, you will see style 1. On the other hand if you load the DLL in a GUI application (with a window), you probably will see style 2.

My question for you is why this happens, why are there 2 different styles? And is it possible to always force the message box to be in a specified style? I personally like style 2 a lot more because it looks more modern, so I would like to always have my message boxes in style 2, but how?


Solution

  • They are different commctrl versions but, as of 2022, there is no point of not using the newer style, nobody would target an older system nowadays.

    Put this to a cpp:

    #if defined _WIN64
    #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
    #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif
    

    and then you get the new styles.