是否有必要使用InitCommonControlsEx()和InitCommonControls()?

kie*_*wic 11 winapi

我对win32完全不熟悉.我在过去的48小时里一直在努力.

我正在尝试构建一个"网格",我在msdn.microsoft.com上获得了List-View控件Header控件的示例 .

第一个调用InitCommonControls()函数(此外我读过这个函数已经过时了).

HWND DoCreateHeader(HWND hwndParent, HINSTANCE hInst) 
{ 
    HWND hwndHeader; 
    RECT rcParent; 
    HDLAYOUT hdl; 
    WINDOWPOS wp; 

    // Ensure that the common control DLL is loaded, and then create 
    // the header control. 
    InitCommonControls(); 

    // ...

    // hwndHeader = CreateWindowEx(0, WC_HEADER, ...
}
Run Code Online (Sandbox Code Playgroud)

第二个调用InitCommonControlsEx()函数.

HWND CreateListView (HWND hwndParent, HINSTANCE hInst) 
{     
    RECT rcl; 
    INITCOMMONCONTROLSEX icex;

    // Ensure that the common control DLL is loaded. 
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC  = ICC_LISTVIEW_CLASSES;
    InitCommonControlsEx(&icex); 

    // ...

    // HWND hWndListView = CreateWindow(WC_LISTVIEW ...
}
Run Code Online (Sandbox Code Playgroud)

似乎这些函数需要comctl32.lib库,但下载它是一团糟.

此外,我注意到如果我删除这些功能,一切都运行良好.那么,他们有必要吗?

谢谢!

Mic*_*ael 10

是的,这是必要的.他们需要获取已注册的自定义控件的窗口类.可能性是,代码中的其他一些组件正在加载它们.我不确定,但我想如果你在清单中支持comctl v6(XP和up视觉样式),你会自动获得commctl32.dll.

有关InitCommonControlsEx的更多信息,请点击此处.

通过下载comctl32.lib不确定你的意思,它自NT 4和Windows 95以来就存在于每个Windows平台上,所以你不需要重新发布它.