【发布时间】:2016-01-08 17:28:20
【问题描述】:
我正在尝试在我的窗口上放置一个简单的超链接。
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC = ICC_LINK_CLASS; // CommCtrl.h: #define ICC_LINK_CLASS 0x00008000
bool bResult = InitCommonControlsEx(&iccx); // bResult is false.
DWORD dwError = GetLastError(); // dwError is 0.
hWnd = CreateWindowExW( /*_In_ DWORD*/ 0,
/*_In_opt_ LPCTSTR*/ WC_LINK, // CommCtrl.h: #define WC_LINK L"SysLink"
/*_In_opt_ LPCTSTR*/ L"Hello World",
/*_In_ DWORD*/ WS_VISIBLE | WS_CHILD | WS_TABSTOP,
/*_In_ int*/ 50,
/*_In_ int*/ 200,
/*_In_ int*/ 100,
/*_In_ int*/ 20,
/*_In_opt_ HWND*/ hWndParent,
/*_In_opt_ HMENU*/ NULL,
/*_In_opt_ HINSTANCE*/ hInstance,
/*_In_opt_ LPVOID*/ NULL);
DWORD dwError = GetLastError(); // hWnd is NULL and dwError is 1407.
错误码1407在here中解释如下。
ERROR_CANNOT_FIND_WND_CLASS
1407 (0x57F)
Cannot find window class.
我使用的是 Windows 8.1 Pro x64,我从未在任何其他版本的 Windows 上尝试过此代码。
这里有什么问题?
【问题讨论】:
-
您忘记了 Common Controls 6 清单吗? SysLink 控件需要 Common Controls 6。
-
@andlabs 第一次听说。我现在谷歌一下。谢谢。
-
经过一些互联网研究,我能够通过在
#include <CommCtrl.h>包含 CommCtrl.h 之后添加代码#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")来解决我的问题。然而,我不知道我做了什么。 -
该行指示 Microsoft 链接器添加 Common Controls 6 清单。有关详细信息,请参阅this page。 Windows 要求您执行此操作以选择加入新版本的通用控件库 for backward compatibility reasons。
标签: c++ winapi hyperlink common-controls createwindow