c++ - InitCommonControlsEx() 在 Windows 8.1 中因 ICC_LINK_CLASS 而失败

标签 c++ winapi hyperlink common-controls createwindow

我正在尝试在我的窗口上放置一个简单的超链接。

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 上尝试过此代码。

这里有什么问题?

最佳答案

如你所想,添加

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

是解决问题的一种方法。

SysLink 控件仅在 Common Controls 版本 6 中添加。backwards compatibility reasons , Common Controls 6 默认情况下未启用。您必须通过创建 list 来选择加入它。

list 可以作为单独的文件(名为 program.exe.manifest)或作为具有特定资源 ID 的资源存在。 #pragma 行告诉 Microsoft 的链接器为您生成第二个。您也可以自己制作任何一种表格。 Here's how.

关于c++ - InitCommonControlsEx() 在 Windows 8.1 中因 ICC_LINK_CLASS 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33060724/

相关文章:

c++ - 是否有用于从另一个不同的 std::array 初始化 std::array 的特定语法?

c++ - 为什么我的程序会跳过 while 循环? 2 大于 -1

javascript - 创建 block 级元素的链接

html - 链接的默认颜色不会改变

c++ - typeid ("") != typeid(const char*)

c++ - 我可以在 Windows 上使用 Asio(非增强)打开超过 2048 个套接字吗?

c++ - 有什么方法可以在考虑崩溃的情况下同步进程吗?

winapi - CMake 找不到 Windows SDK 8.1

c++ - 如何在窗口消息中发送 float

javascript - 从数组随机 URL 重定向