Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my message box look different from those Windows 10 otherwise shows?

I am thinking consistency. I use the MessageBox Windows API function in my Windows subsystem C/C++ application built by Visual Studio 2017, like so:

MessageBox(NULL, "Error opening log file for writing, aborting.", NULL, MB_ICONERROR);

This gets me:

My message box

The message box shown by Windows when I e.g. attempt to run an invalid program using the Run dialog from the Start menu, looks like this:

System message box

It's obviously not a show stopper, but I am curious, and am surprised at this level of lack of consistency in Windows, after all the versions it's gone through. Yes, I know there is a rats nest of backwards compatibility they have to address constantly, but still.

Does this have to do with some settings I haven't specified in my manifest file, some common control styles I am not explicitly requesting? My project and solution settings are untouched, other than having specified DPI Awareness as "Per Monitor DPI aware". Turning the latter off still shows the same message box (albeit with blurry text because the system scales the rendered bitmap, as documented).

The manifest embedded by VS in the built program

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
            </requestedPrivileges>
        </security>
    </trustInfo>
    <asmv3:application>
        <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
            <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
        </asmv3:windowsSettings>
    </asmv3:application>
</assembly>
like image 384
amn Avatar asked Oct 21 '25 11:10

amn


2 Answers

It appears Windows 10/11 uses ShellMessageBox instead of MessageBox to display simple messages. ShellMessageBox has been available since Windows XP and can be invoked as a drop-in replacement for MessageBox.

like image 104
Ed Millerski Avatar answered Oct 24 '25 07:10

Ed Millerski


I needed to explicitly declare dependency on the so-called common controls of version 6, in order for Windows to render the message box with desired style using MessageBox, adding the following to the application manifest:

<dependency>
    <dependentAssembly>
        <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />
    </dependentAssembly>
</dependency>

I don't recall what the publicKeyToken value was all about, or if it is even required. The article at https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests may explain whether it is, indeed, required.

like image 29
amn Avatar answered Oct 24 '25 06:10

amn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!