1.在指定位置处创建一个CMFCTabCtrl,并给其添加4个CEdit,
CRect rectTab;
CEdit m_wnd1;
CEdit m_wnd2;
CEdit m_wnd3;
CEdit m_wnd4;
CMFCTabCtrl m_wndTab;
m_wndTabLoc.GetWindowRect (&rectTab);
ScreenToClient (&rectTab);
m_wndTab.Create (CMFCTabCtrl::STYLE_3D, rectTab, this, 1,
CMFCTabCtrl::LOCATION_TOP);
m_wnd1.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 1);
m_wnd1.SetFont (&afxGlobalData.fontRegular);
m_wnd1.SetWindowText (_T("Edit 1"));
m_wnd2.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 2);
m_wnd2.SetFont (&afxGlobalData.fontRegular);
m_wnd2.SetWindowText (_T("Edit 2"));
m_wnd3.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 3);
m_wnd3.SetFont (&afxGlobalData.fontRegular);
m_wnd3.SetWindowText (_T("Edit 3"));
m_wnd4.Create (WS_CHILD | WS_VISIBLE, CRect (0, 0, 0, 0), &m_wndTab, 4);
m_wnd4.SetFont (&afxGlobalData.fontRegular);
m_wnd4.SetWindowText (_T("Edit 4"));
m_wndTab.AddTab (&m_wnd1, _T("One"), 0, FALSE);
m_wndTab.AddTab (&m_wnd2, _T("Two"), 1, FALSE);
m_wndTab.AddTab (&m_wnd3, _T("Three"), 2, FALSE);
m_wndTab.AddTab (&m_wnd4, _T("Four"), 3, FALSE);
2.为CMFCTabCtrl设置Tab标签的图标:
m_wndTab.SetImageList (IDB_ICONS, 16, RGB (255, 0,255));
m_wndTab.SetTabIcon (nTab, nTab);
m_wndTab.RecalcLayout ();
m_wndTab.RedrawWindow ();
3.设置CMFCTabCtrl的样式:
m_wndTab.ModifyTabStyle (style);
m_wndTab.RecalcLayout ();
m_wndTab.RedrawWindow ();
4.设置CMFCTabCtrl表头的位置(上面还是下面):
m_wndTab.SetLocation (CMFCTabCtrl::LOCATION_BOTTOM);//Tab标签在底部
m_wndTab.SetLocation (CMFCTabCtrl::LOCATION_TOP);//Tab标签在顶部
m_wndTab.RecalcLayout ();
m_wndTab.RedrawWindow ();
5.设置CMFCTabCtrl表头及边框的颜色:
CArray<COLORREF, COLORREF> arColors;
arColors.Add (RGB (121, 210, 231));
arColors.Add (RGB (190, 218, 153));
arColors.Add (RGB (255, 170, 100));
m_wndTab.EnableAutoColor (TRUE);
m_wndTab.SetAutoColors (arColors);
6.设置CMFCTabCtrl表头是否可以拖拽:
m_wndTab.EnableTabSwap (TRUE);//可以拖拽
m_wndTab.EnableTabSwap (FALSE);//不可拖拽