Use CTabCtrl class variable to bind this control, which is set to m_tabctrl here.
2. Create two new dialog resources and modify their properties as follows:
Border:none// The border is empty, so there is no title bar.
Style:child// This template can be used as a child window of another window.
If everything else is unnecessary, there is no need to change it.
Add some controls on it, and the specific operation is no different from ordinary dialog boxes.
When finished, two new dialog classes are generated from these two dialog templates.
3. Add the header file of the new dialog box to. H file, and add two variables for two newly added classes:
For example:
CTabCtrl m _ tabctrl
cdlgtab 1m _ dlgtab 1;
cdlgtab 2m _ dlgtab 2;
4. Add the following code similar to the OnInitDialog () function of the main dialog box:
CRect r; //CRect contains member variables that define the upper left and lower right corners of the rectangle.
m_tabctrl。 GetClientRect(& amp; r);
TC item item 1;
TCITEM item2
item 1 . mask = TCIF _ TEXT;
Item 1.pszText = _T ("first page");
m_tabctrl。 InsertItem( 1,ampitem 1);
item 2 . mask = TCIF _ TEXT;
Item2.pszText = _T ("second page");
m_tabctrl。 InsertItem(2, & item 2);
m_dlgtab 1。 Create (IDD_DLGTAB 1,& ampm _ tab ctrl);
m_dlgtab2。 create(IDD _ dlgtab 2 & amp; m _ tab ctrl);
m_dlgtab 1。 SetWindowPos(NULL, 10,30,r.right - 20,r.bottom - 40,SWP _ show window);
m_dlgtab2。 SetWindowPos(NULL, 10,30,r.right - 20,r.bottom - 40,SWP _ HIDEWINDOW);
m_tabctrl。 SetCurSel(0);
The explanation is as follows:
Call two InsertItem functions to add two tabs to the label control, and the text is the title.
The function is used to set the position of these two dialogs on the Z axis and show or hide their status.
5. Add a control notification message of label selection change (TCN _ selection change) to the label control in the main dialog box, so as to notify the main dialog box when the user selects a label. Right-click the label control in the editing interface of the main dialog box.
, choose to add an event to complete this operation.
Add the following code to the event handling, as shown in the following example:
void CtabdialogDlg::OnSelchangeTimingtab(nm HDR * pNMHDR,LRESULT *pResult)
{
CRect r;
m_tabctrl。 GetClientRect(& amp; r);
switch(m_tabctrl。 GetCurSel())
{
Case 0:
m_mm 1。 SetWindowPos (NULL, 10,30,r.right -20,r.bottom -40,SWP _ show window);
m_mm2。 SetWindowPos (NULL, 10,30,r.right -20,r.bottom -40,SWP _ HIDEWINDOW);
Break;
Case 1:
m_mm 1。 SetWindowPos (NULL, 10,30,r.right -20,r.bottom -40,SWP _ HIDEWINDOW);
m_mm2。 SetWindowPos (NULL, 10,30,r.right -20,r.bottom -40,SWP _ show window);
Break;
}
* pResult = 0;
}
To know which tab the user has selected, you need to use m_tabctrl. GetCurSel () function. In order not to make the displayed sub-dialog box overlap the display of the label control, it is necessary to obtain the size of the label control and then set the size of each page.