1. Add a tab contr control to an existing project
2. Add the variable m_tabctrl to the tab control control
- <span style= "font-family:'Microsoft YaHei', 'Helvetica Neue', SimSun;line-height:21px;background-color:rgb(255,255,255);" >3. The dialog initialization function OnInitDialog in the CXXXDlg class Add the following code inside:</span>
- <span style= "font-family:Arial, Helvetica, sans-serif;" > //Add </span> tab
- m_tabctrl.InsertItem(0,_T( "Page 1" )); //"Tab 1" can be changed and is the name of the sheet page;
- m_tabctrl.InsertItem(1,_T( "Page 2" ));
- m_tabctrl.InsertItem(2,_T( "Page 3" ));
4. In the Dialog in the resource view, right-click on "Dialog", select "Insert Dialog", and insert three Dialogs with IDs named IDD_DIALOG1, IDD_DIALOG2, IDD_DIALOG3. In the properties of each Dialog, the style is Child and the Border is None. , adjust the width . Then add the corresponding C Dialog classes CDia log1 , CDialo g2, CDialog3
5. Add the header files of the above three classes in CXXXDlg.h CDia log1.h CDia log2.h CDia log3.h
6. Add three member variables m_para1, m_para2, m_para3 in turn in CXXXDlg.h, as follows:
- CDialog1 m_para1;
- CDialog2 m_para2;
- CDialog3 m_para3;
- //create screen
- m_para1.Create(IDD_DIALOG1, &m_tabctrl);
- m_para2.Create(IDD_DIALOG2, &m_tabctrl);
- m_para3.Create(IDD_DIALOG3, &m_tabctrl);
7. //Get the size of the tabcontrol client area
- CRect rs;
- m_tabctrl.GetClientRect(&rs);
- //Adjust the position of the child dialog box in the parent window, you can change the value to make the size of the child window appropriate;
- rs.top+=20;
- rs.bottom-=3;
- rs.left+=2;
- rs.right-=2;
- //Set the size of the sub-dialog and move it to the specified position
- m_para1.MoveWindow(&rs);
- m_para2.MoveWindow(&rs);
- m_para3.MoveWindow(&rs);
- // Set hide and show separately
- m_para1.ShowWindow(true);
- m_para2.ShowWindow(false);
- m_para3.ShowWindow(false);
- //set the default tab
- m_tabMain.SetCurSel(0);
7. In the resource view, double-click the Tab Control to add an event handler
- // TODO: Add control notification handler code here
- m_para1.ShowWindow(false);
- m_para2.ShowWindow(false);
- m_para3.ShowWindow(false);
- int CurSel = m_tabMain.GetCurSel ();
- switch(CurSel)
- {
- case 0:
- m_para1.ShowWindow(true);
- break;
- case 1:
- m_para2.ShowWindow(true);
- break;
- case 2:
- m_para3.ShowWindow(true);
- break;<span style="font-family:Arial, Helvetica, sans-serif;">}</span><span style="font-family:Arial, Helvetica, sans-serif;">*pResult = 0</span><span style="font-family:Arial, Helvetica, sans-serif;">;</span>