3

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>
3
  • 2
    The problem seems to be that your application doesn't use the visual themes introduced in Windows XP. You need a proper manifest to enable visual themes. I suppose all your controls are unthemed? Commented Sep 12, 2018 at 10:48
  • I've quoted my manifest. I evidently don't explicitly specify anything that might be related to theming or common control versions. Do I have to? Commented Sep 12, 2018 at 10:57
  • @AndreasRejbrand It seems that you pointed me in the right direction -- requiring Common Controls 6 by specifying so in my manifest, gets me a message box with the same style as the one rendered by the system when attempting to run an invalid program. Feel free to form an answer for me to accept, or I will write one myself (which won't get you any points other than my gratitude). Commented Sep 12, 2018 at 11:38

3 Answers 3

3

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.

1
  • Hey, @Ed, great point. I tried this API and it checks out. This API for sure gives a more modern look to message boxes.
    – yozniak
    Commented Nov 18, 2023 at 19:55
-1

I am not sure that the messagebox shown by windows in your "invalid program" scenario is using MessageBox function or a custom dialog box.
However, in order to achieve consistency maybe you can find an answer here: https://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c14605/Fancy-Custom-MessageBox.htm#page-2

Also, here https://referencesource.microsoft.com/#system.windows.forms/winforms/managed/system/winforms/MessageBox.cs,e426fc24b95c791e you will find how it is implemented - and why the button on the message box is different than in C++ call.

-2

You can use VBScript (.vbs) to make a message box. Write this:

Option Explicit

Dim x

x = MsgBox("Error opening log file for writing. Aborting", VbOkOnly+VbCritical, "Error")
1
  • Welcome to stackoverflow. It is unclear that your answer addresses the OP's question. Please edit your question to include how/whether the message box looks different from Windows 10 message boxes.
    – Simon.S.A.
    Commented Apr 14, 2020 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.