3

好的,所以我对 C++ 和 Windows API 很陌生,我只是在编写一个小应用程序。我希望我的应用程序在 XP、Vista 和 Windows 7 中都使用视觉样式,所以我将这一行添加到我的代码顶部:

#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

它似乎在我的 Windows 7 机器和 Vista 机器上完美运行。但是当我在 XP 上尝试该应用程序时,该应用程序不会加载任何控件(例如按钮、标签等)——甚至不会显示消息框。

此图像显示了一个小型测试应用程序,我刚刚将它放在一起以演示我要解释的内容:http: //img704.imageshack.us/img704/2250/myapp.png

在这个测试应用程序中,我没有使用任何特别花哨或复杂的代码。我实际上只是从 MSDN 库 ( http://msdn.microsoft.com/en-us/library/ff381409.aspx ) 中获取了最基本的示例代码,并在 WM_CREATE 消息中添加了一个部分来创建一个按钮:

MyBtn = CreateWindow(L"Button", L"My Button", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 25, 25, 100, 30, hWnd, NULL, hInst, 0);

但我只是无法弄清楚发生了什么以及为什么它不起作用。有什么想法吗?提前谢谢你。

(顺便说一句,如果我从顶部删除清单部分,应用程序在 XP 中的工作方式 - 显然没有视觉样式。我还应该提到该应用程序是在 Windows 7 机器上使用 Visual C++ 2010 Express 构建的 - 如果这使得区别?)

4

4 回答 4

1
#pragma comment(linker,"/manifestdependency:\"type='win32'...
于 2011-03-07T16:28:01.930 回答
1

在升级到 Win7 和 VC++ 2010 pro 后,我今天也遇到了这个问题。

我首先认为我的清单可能已损坏,最糟糕的是这是我在 VC++ 2010 中的第二个项目,而第一个项目在 Win7 和 XP 上运行良好。

所以我得出结论,在我的程序开头包含 InitCommonControls() 解决了这个问题,为什么?

所以我在我的代码顶部添加了这个:

#include <Commctrl.h>
#pragma comment (lib, "Comctl32.lib")

这在我的初始化代码中:

InitCommonControls();

再加上我在寻找答案,VC+ 2010 现在在控件列表中有 SysLink 控件,这就是我的第一个项目运行良好的原因。将其中之一添加到对话框中,只要添加代码来处理通知,就不需要 Comctl32.lib 和 InitCommonControls 或 InitCommonControlsEx?只要嵌入了带有通用控件的清单,构建的程序也可以在 Win7 和 XP 中运行!

于 2011-03-21T12:30:08.230 回答
1

你打电话给 InitCommonControlsEx 吗?详情在这里

于 2010-05-30T11:18:55.040 回答
0

Hans Passant:

The idea of having the "manifest" included in the executable is to avoid calling the InitCommonControls.

Without the manifest the OS automatically initializes the use of the most "common" comomn controls. And if the manifest is found in the executable resources - exactly those controls are initialized.

Well, I don't know the exact cause of the problem, I only can try to guess.

  • Maybe common controls version 6.0 is not supported in Windows XP (?)
  • Perhaps the manifest must include all the needed controls, not only the version. Vista and may Wnd7 automatically initialize all the "common" common controls of the specified version, whereas Windows XP may not
于 2010-05-30T12:23:26.337 回答