如何在 Windows 上使用默认的 GUI 主题? [英] How do I use the default GUI theme on Windows?

查看:22
本文介绍了如何在 Windows 上使用默认的 GUI 主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 winapi 编写 GUI,但我的应用程序看起来像 Windows 98 主题.如何使用当前的窗口主题?

I am programming a GUI with winapi, but my application looks like Windows 98 theme. How do I use the current window theme?

我试图创建一个清单文件,但它不起作用.

I tried to create a manifest file, but it does not work.

Test.cpp

# include <windows.h>

int WINAPI WinMain(
    HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow
){
    MessageBox(NULL, "Hello World!", "Hello", MB_OK);
    return 0;
}

Test.exe.Manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
  xmlns="urn:schemas-microsoft-com:asm.v1"
  manifestVersion="1.0">
<assemblyIdentity
    name="App.Win.Test"
    processorArchitecture="x86"
    version="1.0.0.0"
    type="win32"/>
<description>Test</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="x86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>

Manifest.rc

1 24 "Test.exe.Manifest"

我在 Windows XP SP3 上用 MinGW 编译器编译.

I compiled with MinGW compiler on Windows XP SP3.

g++ Test.cpp -c
windres Manifest.rc -O coff -o Manifest.res
g++ Test.o Manifest.res -o Test.exe -Wl,-subsystem,windows

但是当我运行可执行文件时,它关闭了.没有清单和资源文件,它可以工作,但使用 Windows 98 主题.

But when I run the executable file, it closes. Without the manifest and resource files, it works, but uses Windows 98 theme.

谢谢

谢谢,现在可以了.

我从教程中复制了清单文件,但没有调用 InitCommonControls().

I copied the manifest fie from a tutorial and I did not call InitCommonControls().

InitCommonControls() 有效.

InitCommonControls() works.

我不得不编辑我的 commctrl.h,因为 InitCommonControlsEx() 在那里被禁用,现在可以工作了.

I had to edit my commctrl.h, because InitCommonControlsEx() was disabled there, and now works.

链接器命令已更改:

g++ Test.o Manifest.res -o Test.exe -Wl,-subsystem,windows -lcomctl32

推荐答案

在调用 MessageBox 之前试试这个代码

Try this code before calling MessageBox

INITCOMMONCONTROLSEX iccx = { sizeof(INITCOMMONCONTROLSEX), ICC_COOL_CLASSES | ICC_BAR_CLASSES};
::InitCommonControlsEx(&iccx);

这篇关于如何在 Windows 上使用默认的 GUI 主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆