gpt4 book ai didi

c++ - 使用 Window API,我如何确保控件保持原生外观?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:16:57 24 4
gpt4 key购买 nike

我创建的一些控件似乎默认为旧的 Windows 95 主题,我该如何防止这种情况发生?这是一个不保留操作系统 native 外观的按钮示例(我使用 Vista 作为我的开发环境):

HWND button = CreateWindowEx(NULL, L"BUTTON", L"OK", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
170, 340, 80, 25, hwnd, NULL, GetModuleHandle(NULL), NULL);

我使用原生 C++ 和 Windows API,没有托管代码。

最佳答案

要向应用程序添加 list ,您需要创建一个 MyApp.manifest 文件并将其添加到应用程序资源文件:

//-- This define is normally part of the SDK but define it if this 
//-- is an older version of the SDK.
#ifndef RT_MANIFEST
#define RT_MANIFEST 24
#endif

//-- Add the MyApp XP Manifest file
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "MyApp.manifest"

对于较新版本的 Visual Studio,项目设置中有一个 Manifest Tool 选项卡,Additional Manifest Files 字段位于该选项卡上选项卡也可用于定义 list 文件。

这是 Win32 应用程序的简单 MyApp.manifest 文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.1"
processorArchitecture="X86"
name="Microsoft.Windows.MyApp"
type="win32"
/>
<description>MyApp</description>
</assembly>

如果您的应用程序依赖于其他 dll,这些详细信息也可以添加到 list 中,Windows 将使用此信息来确保您的应用程序始终使用这些依赖 dll 的正确版本。

例如,这里是公共(public)控件和 8.0 版 C 运行时库的 list 依赖项详细信息:

<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC80.CRT"
version="8.0.50608.0"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b" />
</dependentAssembly>

关于c++ - 使用 Window API,我如何确保控件保持原生外观?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/111630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com