Form creation is complete, let's talk about the use of controls
First in the CFormView form under tab member variables, here I choose the Tab Class Library under MFC: CMFCTabCtrl
class Public cformview{... ...... Public : CMFCTabCtrl m_tab; }
Dynamically create tabs in the initialization and set the style of the tabs, here we use the creat function, his prototype is
Const rect& rect, cwnd* pParentWnd, UINT nID, location location = Location_bottom, BOOL bclosebtn = FALSE);
The first parameter is a style style
is an enumeration type that defines the style of the tab, which is basically a 3D style
Public:
CMFCTabCtrl ();
EnumStyle
{
Style_3d =0,
Style_flat =1,
Style_flat_shared_horz_scroll =2,
style_3d_scrolled =3,
Style_3d_onenote = 4,
style_3d_vs2005 = 5,
style_3d_rounded = 6,
Style_3d_rounded_scroll = 7,
};
Second parameter: Setting the TAB size
Third parameter: Form handle
Fourth parameter: Set tab control ID
Fifth parameter: Set tab label position, MFC only gives the top and bottom two directions to display tab label location
Public
CMFCBaseTabCtrl ();
Enum location
{
Location_bottom = 0,
Location_top = 1
};
The sixth parameter: whether with the Close button, the logic of the Close button is to be implemented by itself, this we say next.
To add a tab code:
void ctabview::oninitialupdate ()
{
Cformview::oninitialupdate ();
GetParentFrame (),recalclayout ();
ResizeParentToFit ();
CRect RC;
GetClientRect (RC);
Cmfctabctrl::resize_horiz, Cmfctabctrl::location_top))
{
Return
}
}
Creating a good selection of video cards is bare without any tab, this requires us to manually add
How to create tabs for tabs, which requires our new form to be displayed in tabs
Create a three dialog form fallback
Add a class to the form and auto-generate it to
After that we add tabs to the tabs and reference the pointers to the new dialog class that we just created in the tab
" Dialog1.h " "Dialog2.h""Dialog3.h"class public cformview{ public: CMFCTabCtrl m_tab; *M_dlg1; *m_dlg2; *M_dlg3;}
Forms that are created dynamically during program initialization
void Ctabview::oninitialupdate ()
{
Cformview::oninitialupdate ();
GetParentFrame ()->recalclayout ();
ResizeParentToFit ();
CRect RC;
GetClientRect (RC);
if (!m_tab. Create (Cmfctabctrl::style_3d_onenote, RC, this, cmfctabctrl::location_top,0))
{
return;
}
M_dlg1=new CDialog1;
M_dlg2=new CDialog2;
M_dlg3=new CDialog3;
M_dlg1->create (Idd_dialog1,&m_tab);
M_dlg1->setfont (&afxglobaldata.fontregular);
M_DLG1->SETWINDOWTEXTW (L "Listctrl control");
M_dlg2->create (Idd_dialog2,&m_tab);
M_dlg2->setfont (&afxglobaldata.fontbold);
M_DLG2->SETWINDOWTEXTW (L "Haven't thought of any more controls");
M_dlg3->create (Idd_dialog3,&m_tab);
M_dlg3->setfont (&afxglobaldata.fontdefaultguibold);
/*M_DLG3->SETWINDOWTEXTW (L "What controls are more difficult to write");
M_tab. AddTab (m_dlg1,l "Listctrl control");
M_tab. AddTab (m_dlg2,l "not yet thought of any control");
M_tab. AddTab (m_dlg3,l "is there any control more difficult to write?");
M_tab. Enableactivetabclosebutton ();//Whether to add the Close tab button
M_tab. SetActiveTab (0); Activates the tab with the current tab as the first page.
}
Run for a look at the effect
It seems to be possible, but when we click on the tab, we will find that our form is not embedded, because we are missing a step, causing the form to open when it is created by pop-up.
Open the form properties, change the Style property from popup Popup to child window, and all of the labels use the form to change this
Effect
The inside of the form is too ugly, the border and the title to remove it just fine
Form properties, change the border to none.
Final effect
How to write gracefully ui--(3) Add MFC tab