1.The Common Controls
Control Type | WNDCLASS | WNDCLASS Alias | MFC Class |
---|---|---|---|
Animation | "SysAnimate32" | ANIMATE_CLASS | CAnimateCtrl |
ComboBoxEx* | "ComboBoxEx32" | WC_COMBOBOXEX | CComboBoxEx |
Date-Time* | "SysDateTimePick32" | DATETIMEPICK_CLASS | CDateTimeCtrl |
Header | "SysHeader32" | WC_HEADER | CHeaderCtrl |
Hotkey | "msctls_hotkey32" | HOTKEY_CLASS | CHotKeyCtrl |
Image list | N/A | N/A | CImageList |
IP address** | "SysIPAddress32" | WC_IPADDRESS | CIPAddressCtrl |
List view | "SysListView32" | WC_LISTVIEW | CListCtrl |
Month calendar* | "SysMonthCal32" | MONTHCAL_CLASS | CMonthCalCtrl |
Progress | "msctls_progress32" | PROGRESS_CLASS | CProgressCtrl |
Property sheet | N/A | N/A | CPropertySheet |
Rebar* | "ReBarWindow32" | REBARCLASSNAME | CReBarCtrl |
Rich edit | "RichEdit20A" (ANSI) or "RichEdit20W" (Unicode) | RICHEDIT_CLASS | CRichEditCtrl |
Slider | "msctls_trackbar32" | TRACKBAR_CLASS | CSliderCtrl |
Spin button | "msctls_updown32" | UPDOWN_CLASS | CSpinButtonCtrl |
Status bar | "msctls_statusbar32" | STATUSCLASSNAME | CStatusBarCtrl |
Tab | "SysTabControl32" | WC_TABCONTROL | CTabCtrl |
Toolbar | "ToolbarWindow32" | TOOLBARCLASSNAME | CToolBarCtrl |
ToolTip | "tooltips_class32" | TOOLTIPS_CLASS | CToolTipCtrl |
Tree view | "SysTreeView32" | WC_TREEVIEW | CTreeCtrl |
* Requires Internet Explorer 3.0 or later.
** Requires Internet Explorer 4.0 or later.
2.Creating a Common Control
1)
#include <afxcmn.h>
CProgressCtrl wndProgress;
wndProgress.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER,CRect (x1, y1, x2, y2), this, IDC_PROGRESS);
2)
CONTROL "", IDC_PROGRESS, PROGRESS_CLASS, WS_BORDER, 32, 32, 80, 16
Once you've created a common control, you manipulate it using member functions of the corresponding control class.
DDX_Control (pDX, IDC_PROGRESS, m_wndProgress);//This statement must appear in a dialog class's DoDataExchange function.
When you use the common controls in an SDK-style application, you must call either ::InitCommonControls or the newer ::InitCommonControlsEx to load Comctl32.dll and register the controls' WNDCLASSes before creating the first control. In an MFC application, MFC calls these functions for you.
3.Processing Notifications: The WM_NOTIFY Message
typedef struct _NM_TREEVIEW {
NMHDR hdr;
UINT action;
TV_ITEM itemOld;
TV_ITEM itemNew;
POINT ptDrag;
} NM_TREEVIEW;
typedef struct _TV_DISPINFO {
NMHDR hdr;
TV_ITEM item;
} TV_DISPINFO;
How do you know what pointer was cast by lParam?
1)
NMHDR* pnmh = (NMHDR*) lParam;
switch (pnmh->code) {
case TVN_ITEMEXPANDED:
NM_TREEVIEW* pnmtv = (NM_TREEVIEW*) pnmh;
// Process the notification.
break;
case TVN_GETDISPINFO:
NM_DISPINFO* pnmdi = (NM_DISPINFO*) pnmh;
// Process the notification.
break;
}
2)
ON_NOTIFY (TVN_ITEMEXPANDED, IDC_TREEVIEW, OnItemExpanded)
ON_NOTIFY (TVN_GETDISPINFO, IDC_TREEVIEW, OnGetDispInfo)
void CMyWindow::OnItemExpanded (NMHDR* pnmh, LRESULT* pResult)
{
NM_TREEVIEW* pnmtv = (NM_TREEVIEW*) pnmh;
// Process the notification.
}
void CMyWindow::OnGetDispInfo (NMHDR* pnmh, LRESULT* pResult)
{
NM_DISPINFO* pnmdi = (NM_DISPINFO*) pnmh;
// Process the notification.
}