1.Create a newMFCEngineering, nameMytab,SelectDialog based,thenFinish.?
2.Delete Three controls added by default on a dialog box. AddTab Controlcontrol and in Propertyproperty, setIDto beidc_tabtestin theMore Stylesinside the hookBottom.Speed up the size of the dialog box, My SideTab Controlthe dimensions last for164x203.in theClassWizardadd a variable to it, variable is namedM_tab.type isCTabCtrl.?
3.The initialization function in the dialog boxOnInitDialogAdd the following code inside:?
M_tab. InsertItem (0, "parameter One");? //Add parameter one tab?
M_tab. InsertItem (1, "parameter Two");? //Add parameter two tabs?
M_tab. InsertItem (2, "Results");??? //Add Results Tab
4.Add Three dialog resources to a dialog resource, IDnamed respectively asidd_para1, Idd_para2, Idd_result.the font is the song body, Font size is9, Styleto beChild , Borderto beNone,width adjustment to161.Add the corresponding basedCDialogclassCPara1, CPara2, Cresult.?
5.in theCmytabdlgThree member variables are added to a classm_para1, M_para2, M_result,is an instance of three sub-dialog boxes, respectively. The code is as follows:
Cresult m_result;?
CPara2 m_para2;?
CPara1 m_para1;?
6.in theIdd_para1dialog box, add the static text control content to"parameter One" then insert a text box control in the back, withClassWizardAssociate it as ainttype variable,name ism_npara1;?
in theIdd_para2dialog box, add the static text control content to"parameter Two" then insert a text box control in the back, withClassWizardAssociate it as ainttype variable,name isM_npara2;?
in theIdd_resultdialog box, add the static text control content to"Results" then insert a text box control in the back, withClassWizardAssociate it as ainttype variable,name isM_nresult;?
7.to beCPara1class to add member functionsint Getparavalue ()The code is as follows:?
int Cpara1::getparavalue ()?
... {?
? return m_npara1;?
}?
to beCPara2class to add member functionsint Getparavalue ()The code is as follows:?
int Cpara2::getparavalue ()?
... {?
? return M_NPARA2;?
}?
to beCresultclass to add member functionsvoid Setresultvalue (int nresult)The code is as follows:?
void Cresult::setresultvalue (int nresult)?
... {?
???? M_nresult = Nresult;?
}?
8.in theIdd_mytab_dialogthe initialization function of the dialog boxOnInitDialogAdd the following code inside:?
//Association dialog box,and Willidc_tabtestcontrol is set to parent window?
M_para1. Create (Idd_para1,getdlgitem (idc_tabtest));?
M_para2. Create (Idd_para2,getdlgitem (idc_tabtest));?
M_result. Create (Idd_result,getdlgitem (idc_tabtest));?
?
//Getidc_tabtestclient Area size?
CRect rs;?
M_tab. GetClientRect (&RS);?
//adjust the position of the Child dialog box in the parent window?
rs.top+=1;?
rs.bottom-=60;?
rs.left+=1;?
rs.right-=2;?
?
//sets the size of the child dialog box and moves to the specified position?
M_para1. MoveWindow (&RS);?
M_para2. MoveWindow (&RS);?
M_result. MoveWindow (&RS);?
?
//set hide and show separately?
M_para1. ShowWindow (true);?
M_para2. ShowWindow (false);?
M_result. ShowWindow (false);?
?
//Set the default tab?
M_tab. SetCurSel (0);
9. Add the tcn_selchange Event response function for the Tab control Onselchangetabtest (nmhdr* pnmhdr, lresult* pResult), the function body code is as follows :
int Cursel = M_tab. GetCurSel ();?
? switch (Cursel)?
?... {?
? case 0:? The
???????? M_para1. ShowWindow (true);? The
???????? M_para2. ShowWindow (false);? The
???????? M_result. ShowWindow (false);?
? break;?
? Case 1:? The
???????? M_para1. ShowWindow (false);? The
???????? M_para2. ShowWindow (true);? The
???????? M_result. ShowWindow (false);?
? break;?
? Case 2:? The
???????? M_para1. ShowWindow (false);? The
???????? M_para2. ShowWindow (false);? The
???????? M_result. ShowWindow (true);?
? break;?
? Default:?
????????;?
????}?????
?
??? *presult = 0;
under the idd_mytab_dialog dialog box, add a button titled " calculate " Add an event response function to it , The code is as follows :
M_para1. UpdateData (true);?
???? M_para2. UpdateData (true);?
???? M_result. Setresultvalue (m_para1. Getparavalue () +m_para2. Getparavalue ());?
???? M_result. UpdateData (false);?
Detailed use of the C + + MFC Tab control