VS_MFC: tabctrl control application

1. Add a tab contr control to an existing project

2. Add the variable m_tabctrl to the tab control control

[cpp]  view plain copy  
  1. <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>  
[cpp]  view plain copy  
  1. <span style= "font-family:Arial, Helvetica, sans-serif;" > //Add </span> tab  
  2. m_tabctrl.InsertItem(0,_T( "Page 1" )); //"Tab 1" can be changed and is the name of the sheet page;  
  3. m_tabctrl.InsertItem(1,_T( "Page 2" ));  
  4. 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:

[cpp]  view plain copy  
  1. CDialog1 m_para1;  
  2. CDialog2 m_para2;  
  3. CDialog3 m_para3;  
  4. //create screen  
  5. m_para1.Create(IDD_DIALOG1, &m_tabctrl);    
  6. m_para2.Create(IDD_DIALOG2, &m_tabctrl);   
  7. m_para3.Create(IDD_DIALOG3, &m_tabctrl);   

7. //Get the size of the tabcontrol client area

[cpp]  view plain copy  
  1. CRect rs;  
  2. m_tabctrl.GetClientRect(&rs);  
  3. //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;  
  4. rs.top+=20;  
  5. rs.bottom-=3;  
  6. rs.left+=2;  
  7. rs.right-=2;  
  8. //Set the size of the sub-dialog and move it to the specified position  
  9. m_para1.MoveWindow(&rs);  
  10. m_para2.MoveWindow(&rs);  
  11. m_para3.MoveWindow(&rs);  
  12. // Set hide and show separately  
  13. m_para1.ShowWindow(true);  
  14. m_para2.ShowWindow(false);  
  15. m_para3.ShowWindow(false);  
  16. //set the default tab  
  17. m_tabMain.SetCurSel(0);  

7. In the resource view, double-click the Tab Control to add an event handler

[cpp]  view plain copy  
  1. // TODO: Add control notification handler code here  
  2. m_para1.ShowWindow(false);  
  3. m_para2.ShowWindow(false);  
  4. m_para3.ShowWindow(false);  
  5. int  CurSel = m_tabMain.GetCurSel ();  
  6. switch(CurSel)  
  7. {  
  8. case 0:  
  9. m_para1.ShowWindow(true);  
  10. break;  
  11. case 1:  
  12. m_para2.ShowWindow(true);  
  13. break;  
  14. case 2:  
  15. m_para3.ShowWindow(true);  
  16. 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>  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326008920&siteId=291194637