2015-10-11 22 views
0

我試圖在我的窗口上放一個簡單的超鏈接。InitCommonControlsEx()在Windows 8.1中ICC_LINK_CLASS失敗

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上嘗試過這些代碼。

這裏有什麼問題?

+4

您忘記了共同控制6清單嗎? SysLink控件需要公共控件6. – andlabs

+0

@andlabs第一次聽到它。我現在將谷歌它。謝謝。 – hkBattousai

+0

經過一番網絡調查,我能夠通過添加代碼#pragma comment(linker,/ manifestdependency:\「type ='win32'name ='Microsoft.Windows.Common-Controls'version =' 6.0.0.0'processorArchitecture ='*'publicKeyToken ='6595b64144ccf1df'language ='*'\「」)''在包含CommCtrl.h'#include '之後。然而,我不知道我做了什麼的解釋。 – hkBattousai

回答

1

正如你已經想通了,加入

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

是解決這個問題的方法之一。

SysLink控件僅在公共控件版本6中添加。對於backwards compatibility reasons,公共控件6默認情況下未啓用。你必須通過創建一個清單來選擇它。

清單可以作爲單獨的文件(名爲program.exe.manifest)或作爲具有特定資源ID的資源而存在。 #pragma行告訴微軟的鏈接器爲你生成第二個。你也可以自己製作任何一種形式。 Here's how.