Q: How to register Windows Common Controls in a Win32 application?
A: You must register the control classes from the common control DLL ('comctl32.dll'):
- include 'commctrl.h' header file;
- link your project to 'comctl32.lib', e.g. using '#pragma' comment
- call 'InitCommonControlsEx()'
Code:#include <windows.h> #include <commctrl.h> #include <resource.h> BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); void RegisterCommonControls(); #pragma comment(lib, "comctl32.lib") void RegisterCommonControls() { INITCOMMONCONTROLSEX iccex; iccex.dwSize = sizeof(INITCOMMONCONTROLSEX); iccex.dwICC = ICC_TREEVIEW_CLASSES // tree view and tooltip control classes | ICC_LISTVIEW_CLASSES; // list view and header control classes // see INITCOMMONCONTROLSEX in MSDN for a complete list InitCommonControlsEx(&iccex); } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { RegisterCommonControls(); INT_PTR nRet = DialogBox(hInstance, // handle to module MAKEINTRESOURCE(IDD_DIALOG1), // dialog box template NULL, // handle to owner window DialogProc); // dialog box procedure return 0; }


Reply With Quote

Bookmarks