The study of Programming Windows with MFC--Common Control

1.The Common Controls

Control TypeWNDCLASSWNDCLASS AliasMFC Class
Animation"SysAnimate32"ANIMATE_CLASSCAnimateCtrl
ComboBoxEx*"ComboBoxEx32"WC_COMBOBOXEXCComboBoxEx
Date-Time*"SysDateTimePick32"DATETIMEPICK_CLASSCDateTimeCtrl
Header"SysHeader32"WC_HEADERCHeaderCtrl
Hotkey"msctls_hotkey32"HOTKEY_CLASSCHotKeyCtrl
Image listN/AN/ACImageList
IP address**"SysIPAddress32"WC_IPADDRESSCIPAddressCtrl
List view"SysListView32"WC_LISTVIEWCListCtrl
Month calendar*"SysMonthCal32"MONTHCAL_CLASSCMonthCalCtrl
Progress"msctls_progress32"PROGRESS_CLASSCProgressCtrl
Property sheetN/AN/ACPropertySheet
Rebar*"ReBarWindow32"REBARCLASSNAMECReBarCtrl
Rich edit"RichEdit20A" (ANSI) or "RichEdit20W" (Unicode) RICHEDIT_CLASSCRichEditCtrl
Slider"msctls_trackbar32"TRACKBAR_CLASSCSliderCtrl
Spin button"msctls_updown32"UPDOWN_CLASSCSpinButtonCtrl
Status bar"msctls_statusbar32"STATUSCLASSNAMECStatusBarCtrl
Tab"SysTabControl32"WC_TABCONTROLCTabCtrl
Toolbar"ToolbarWindow32"TOOLBARCLASSNAMECToolBarCtrl
ToolTip"tooltips_class32"TOOLTIPS_CLASSCToolTipCtrl
Tree view"SysTreeView32"WC_TREEVIEWCTreeCtrl

* 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.
  }


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风水月

从心底相信自己是成功的第一步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值