简体   繁体   中英

How do I implement Windows style for a dialog box in C++?

I have searched for an answer on the Internet, but with exceptions of the difference between modal and modaless dialog boxes, I couldn't find anything useful for my question.

As written in the title, my question is - how can I implement/use a Windows version specific design for my dialog box? IOW, use the Windows 10 button style on a Windows 10 system.

I am using Visual Studio, and I have created a simple resource for my dialog using the integrated resource editor.

Here is my programm:

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, NULL);
    system("pause");
    return 0;
}

Right now, when I compile this code, the console and the dialog box appear on the screen, but the dialog box controls (buttons) seem to be shown in the Windows 2000 style. I'm using Windows 10.

I have this style:

目前的风格

I want this style:

想要的风格

You need to opt in to comctl32 v6 in your manifest: Enabling Visual Styles .

To enable your application to use visual styles, you must use ComCtl32.dll version 6 or later. Because version 6 is not redistributable, it is available only when your application is running on a version of Windows that contains it. Windows ships with both version 5 and version 6. ComCtl32.dll version 6 contains both the user controls and the common controls. By default, applications use the user controls defined in User32.dll and the common controls defined in ComCtl32.dll version 5. For a list of DLL versions and their distribution platforms, see Common Control Versions.

If you want your application to use visual styles, you must add an application manifest or compiler directive that indicates that ComCtl32.dll version 6 should be used if it is available.

An application manifest enables an application to specify which versions of an assembly it requires. In Microsoft Win32, an assembly is a set of DLLs and a list of versionable objects that are contained within those DLLs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM