Use of the tab control
1 Data items that insert the tab control (label)
Ctabctrl::insertitem
2 Creating a dialog box for the parent window with the tab control
3 Resizing dialog box
4 in the tab control's Selchange message handler function, the Display status of the dialog box is set according to the index of the current option.
Create a new project based on the dialog box, drag and drop a tab control, ctrl+w to bind a control variable M_wndtabctrl
Insert Two dialog resource as label page, note that the style of setting them is: Child and no border
Double-click the dialog box resource to add the related class to them, and the parent class uses the default CDialog
This class is named CDialog1 and CDIALOG2
Come to Pig dialog class add the header file of the newly created dialog class, and then add two member variables of that type:
CDialog1 M_dlg1;
CDIALOG2 M_dlg2;
Then go to the OnInitDialog function in the main dialog box to add the creation code, note that the two dialog box members are created with the main dialog box for the parent class.
The code is as follows:
BOOL Ctabctrldlg::oninitdialog () {........................ ...
.
.... ... Todo:add Extra initialization here
//Adds a label to the tab control
m_wndtab.insertitem (0, "Tab1");
M_wndtab.insertitem (0, "Tab2");
Use the tab control to create two dialog boxes for the parent window
M_DLG1. Create (Idd_dialog1, this);
M_dlg2. Create (idd_dialog2, this);
Displays the first dialog box
M_dlg1. ShowWindow (sw_show);
Resize the dialog box
//Get the tab control size
CRect RT;
M_wndtab.getclientrect (&RT);
Rt.top + +;
Rt.left + +;
Rt.right-= 1;
Rt.bottom-= 1;
Sets the size M_DLG1 for each dialog box
. MoveWindow (&RT);
M_dlg2. MoveWindow (&RT);
Displays the first dialog box
M_dlg1. ShowWindow (sw_show);
return TRUE; Return TRUE unless your set the focus to a control
}
Of course, to add tcn_selchange message processing to the tab control in order to enable the note page to function as a toggle
void Cmfctabctroldlg::onselchangetab1 (nmhdr* pnmhdr, lresult* pResult)
{
//Todo:add your control notification Handler code here
//Get the current selection
int nitem = M_wndtabctrl.getcursel ();
Switch (nitem)
{case
0:
m_dlg1. ShowWindow (sw_show);
M_dlg2. ShowWindow (sw_hide);
break;
Case 1:
m_dlg2. ShowWindow (sw_show);
M_dlg1. ShowWindow (sw_hide);
break;
*presult = 0;
}