CMFCTabCtrl的使用

1.在指定位置处创建一个CMFCTabCtrl,并给其添加4个CEdit,

01 CRect rectTab;
02 CEdit m_wnd1;
03 CEdit m_wnd2;
04 CEdit m_wnd3;
05 CEdit m_wnd4;
06 CMFCTabCtrl m_wndTab;
07  
08 m_wndTabLoc.GetWindowRect (&rectTab);
09 ScreenToClient (&rectTab);
10  
11 m_wndTab.Create (CMFCTabCtrl::STYLE_3D, rectTab, this, 1,
12     CMFCTabCtrl::LOCATION_TOP);
13  
14 m_wnd1.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 1);
15 m_wnd1.SetFont (&afxGlobalData.fontRegular);
16 m_wnd1.SetWindowText (_T("Edit 1"));
17  
18 m_wnd2.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 2);
19 m_wnd2.SetFont (&afxGlobalData.fontRegular);
20 m_wnd2.SetWindowText (_T("Edit 2"));
21  
22 m_wnd3.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 3);
23 m_wnd3.SetFont (&afxGlobalData.fontRegular);
24 m_wnd3.SetWindowText (_T("Edit 3"));
25  
26 m_wnd4.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 4);
27 m_wnd4.SetFont (&afxGlobalData.fontRegular);
28 m_wnd4.SetWindowText (_T("Edit 4"));
29  
30 m_wndTab.AddTab (&m_wnd1, _T("One"), 0, FALSE);
31 m_wndTab.AddTab (&m_wnd2, _T("Two"), 1, FALSE);
32 m_wndTab.AddTab (&m_wnd3, _T("Three"), 2, FALSE);
33 m_wndTab.AddTab (&m_wnd4, _T("Four"), 3, FALSE);

2.为CMFCTabCtrl设置Tab标签的图标:

1 m_wndTab.SetImageList (IDB_ICONS, 16, RGB (255, 0,255));
2 m_wndTab.SetTabIcon (nTab, nTab);
3 m_wndTab.RecalcLayout ();
4 m_wndTab.RedrawWindow ();

3.设置CMFCTabCtrl的样式:

1 m_wndTab.ModifyTabStyle (style);
2 m_wndTab.RecalcLayout ();
3 m_wndTab.RedrawWindow ();

4.设置CMFCTabCtrl表头的位置(上面还是下面):

1 m_wndTab.SetLocation (CMFCTabCtrl::LOCATION_BOTTOM);//Tab标签在底部
2 m_wndTab.SetLocation (CMFCTabCtrl::LOCATION_TOP);//Tab标签在顶部
3 m_wndTab.RecalcLayout ();
4 m_wndTab.RedrawWindow ();

5.设置CMFCTabCtrl表头及边框的颜色:

1 CArray<COLORREFCOLORREF> arColors;
2  
3 arColors.Add (RGB (121, 210, 231));
4 arColors.Add (RGB (190, 218, 153));
5 arColors.Add (RGB (255, 170, 100));
6  
7 m_wndTab.EnableAutoColor (TRUE);
8 m_wndTab.SetAutoColors (arColors);

6.设置CMFCTabCtrl表头是否可以拖拽:

1 m_wndTab.EnableTabSwap (TRUE);//可以拖拽
2 m_wndTab.EnableTabSwap (FALSE);//不可拖拽

posted @ 2011-06-28 14:38  心随灵动  阅读(4290)  评论(0编辑  收藏  举报