Win32控件的分类
这里先不讨论ImageList等控件组件、对话框等,只讨论有类型名称的Win32控件。
可以从下边的列表看出来,大部分控件的宏定义名称都是以WC_开头的,另外有8个是以_CLASS结尾的,工具栏、状态栏、ReBar则是以CLASSNAME结尾。
这些控件所需要的加载代码是不同的:
除此之外,预定义控件大多使用WM_COMMAND等比较老的通知消息;而通用控件大多使用WM_NOTIFY等比较新的通知消息,富文本框则两者都有。但是也并不总是这样的,比如加载comctl32.dll v6.0以后,部分预定义控件也会发出WM_NOTIFY消息。
预定义控件(user32.dll):
<code class="language-txt">WC_BUTTON "BUTTON" // Button,CheckBox,RadioButton,GroupBox WC_COMBOBOX "COMBOBOX" WC_EDIT "EDIT" WC_LISTBOX "LISTBOX" WC_SCROLLBAR "SCROLLBAR" // Horizontal,Vertical WC_STATIC "STATIC" // StaticText,PictureControl </code>
富文本框(richedit.dll、riched20.dll、msftedit.dll):
<code class="language-txt">RICHEDIT_CLASS10A "RICHEDIT" // richedit.dll RICHEDIT_CLASS(A/W) "RichEdit20A/W" // riched20.dll MSFTEDIT_CLASS "RICHEDIT50W" // msftedit.dll (WinXPSP1+) </code>
Win95通用控件(comctl32.dll v4.0):
<code class="language-txt">WC_LISTVIEW "SysListView32" // 0x0001 WC_HEADER "SysHeader32" // 0x0001 WC_TREEVIEW "SysTreeView32" // 0x0002 WC_TABCONTROL "SysTabControl32" // 0x0008 TOOLBARCLASSNAME "ToolbarWindow32" // 0x0004 STATUSCLASSNAME "msctls_statusbar32 // 0x0004 TRACKBAR_CLASS "msctls_trackbar32" // 0x0004 UPDOWN_CLASS "msctls_updown32" // 0x0010 PROGRESS_CLASS "msctls_progress32" // 0x0020 HOTKEY_CLASS "msctls_hotkey32" // 0x0040 ANIMATE_CLASS "SysAnimate32" // 0x0080 TOOLTIPS_CLASS "tooltips_class32" // 0x0002,0x0004,0x0008 </code>
IE3.0通用控件(comctl32.dll v4.70):
<code class="language-txt">WC_COMBOBOXEX "ComboBoxEx32" // 0x0200 REBARCLASSNAME "ReBarWindow32" // 0x0400 MONTHCAL_CLASS "SysMonthCal32" // 0x0100 DATETIMEPICK_CLASS "SysDateTimePick32" // 0x0100 </code>
Win98/IE4.0通用控件(comctl32.dll v4.71,v4.72,v5.80,v5.81,v5.82):
<code class="language-txt">WC_IPADDRESS "SysIPAddress32" // 0x0800 WC_PAGESCROLLER "SysPager" // 0x1000 WC_NATIVEFONTCTL "NativeFontCtl" // 0x2000 (这个控件好像没有官方介绍) </code>
WinXP/Vista通用控件(comctl32.dll v6.0):
<code class="language-txt">(重新注册预定义控件) // 0x4000 (comctl32.dll v6.0, WinXP+, 自动) WC_LINK "SysLink" // 0x8000 (comctl32.dll v6.0, WinXP+, 自动) WC_BUTTON "BUTTON" // SplitButton,CommandLink (comctl32.dll v6.0, WinVista+, 自动) </code>
WinVista网络地址控件(shell32.dll):
<code class="language-txt">WC_NETADDRESS "msctls_netaddress" // shell32.dll (WinVista+) </code>
comctl32.dll用5.82还是6.0
现在的系统上通用控件库有两个版本,comctl32 v5.82和comctl32 v6.0。两者的区别主要是以下几点:
5.82已经包含了绝大多数程序逻辑所必需的功能。6.0风格经常跟着系统变,还需要manifest,用起来确实麻烦一些。
如果比较在意程序风格的统一性和兼容性,建议使用5.82;如果比较在意程序的美观性,也可以使用6.0。
完整集成所有标准控件的代码:
<code class="language-cpp">#include <windows.h> #include <tchar.h> #include <windowsx.h> #include <commctrl.h> #include <commdlg.h> #pragma comment(lib, "comctl32.lib") INT_PTR CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, _TCHAR *szCmdLine, int nShowCmd) { // comctl32.dll v6.0 if exists #ifdef USE_COMCTL32_V6 #if defined _M_IX86 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_IA64 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_X64 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") #else #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #endif #endif // comctl32.dll v4.70-5.81 compatible HMODULE hcomctl32 = LoadLibrary(TEXT("comctl32.dll")); INITCOMMONCONTROLSEX icc = { sizeof icc }; typedef BOOL(WINAPI*TInitCommonControlsEx)(LPINITCOMMONCONTROLSEX); TInitCommonControlsEx pInitCommonControlsEx = NULL; if (hcomctl32) pInitCommonControlsEx = (TInitCommonControlsEx)GetProcAddress(hcomctl32, "InitCommonControlsEx"); if (pInitCommonControlsEx) for (int i = 0; i < 16; i++) icc.dwICC = 1 << i, pInitCommonControlsEx(&icc); // riched32.dll,riched20.dll,msftedit.dll LoadLibrary(TEXT("riched32.dll")); LoadLibrary(TEXT("riched20.dll")); LoadLibrary(TEXT("msftedit.dll")); // shell32.dll HMODULE hshell32 = LoadLibrary(TEXT("shell32.dll")); FARPROC pInitNetworkAddressControl = NULL; if (hshell32) pInitNetworkAddressControl = GetProcAddress(hshell32, "InitNetworkAddressControl"); if (pInitNetworkAddressControl) pInitNetworkAddressControl(); DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, NULL); return 0; } </commdlg.h></commctrl.h></windowsx.h></tchar.h></windows.h></code>
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |