Detailed usage of MFC Tab control controls in C + +

Source: Internet
Author: User

This article mainly introduces the MFC Tab control in C + + in the use of detailed information, the need for friends can refer to the

1. Create a new MFC project, named Mytab, choose Dialog based, then finish.

2. Delete the three controls that are added by default on the dialog box. Add tab control controls and set the ID to idc_tabtest in the property attribute bottom in the more styles. The size of the speed control to make it full of dialog box, my side of the tab control is the final 164x203. Add a variable to it in ClassWizard and the variable is named M_tab. Type is CTabCtrl.

3. Add the following code in the initialization function OnInitDialog of the dialog box:

?

1 2 3 M_tab. InsertItem (0, "parameter One"); Add parameter one tab m_tab. InsertItem (1, "parameter Two"); Add parameter two tab m_tab. InsertItem (2, "results"); Add Results tab

4. Add three dialog box resources in the dialog resource, named Idd_para1, Idd_para2, Idd_result, respectively. The font is Arial, the font size is 9, the style is child, the border is none, and the width is adjusted to 161. Then add the corresponding based on CDialog class CPara1, CPara2, Cresult respectively.

5. Add three member variables to the Cmytabdlg class M_para1, M_para2, M_result, which is an instance of three child dialog boxes respectively. The code is as follows:

?

1 2 3 Cresult M_result; CPara2 M_para2; CPara1 M_para1;

6. Add a static text control on the Idd_para1 dialog box to "parameter one" and then insert a text box control, with ClassWizard to associate it with an int variable, named m_npara1;

Add a static text control on the Idd_para2 dialog box to "parameter two" and then insert a text box control, with ClassWizard to associate it with an int variable, named m_npara2;

Add a static text control on the Idd_result dialog box to "result" and then insert a text box control, with ClassWizard to associate it with an int variable, named M_nresult;

7. Add the member function int getparavalue () code for the CPara1 class as follows:

?

1 2 3 4 int Cpara1::getparavalue () ... {return m_npara1;}

Add a member function int getparavalue () code for the CPara2 class as follows:

?

1 2 3 4 int Cpara2::getparavalue () ... {return m_npara2;}

Add a member function void Setresultvalue (int nresult) code for the Cresult class as follows:

?

1 2 3 4 void Cresult::setresultvalue (int nresult) ... {m_nresult = Nresult;}

8. Add the following code in the initialization function OnInitDialog of the Idd_mytab_dialog dialog box:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 The 25 26 association dialog box, and set the Idc_tabtest control as the 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)); Obtain idc_tabtest client area size CRect RS; M_tab. GetClientRect (&RS); Adjusts 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 child dialog box dimensions and moves to the specified location M_PARA1. MoveWindow (&RS); M_para2. MoveWindow (&RS); M_result.   MoveWindow (&RS); Set the hide and display m_para1 separately. ShowWindow (TRUE); M_para2. ShowWindow (FALSE); M_result.   ShowWindow (FALSE); Set the default tab m_tab. SetCurSel (0);

9. Add the tab control's Tcn_selchange event response function onselchangetabtest (nmhdr* pnmhdr, lresult* pResult), the function body code is as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22-23 int Cursel = M_tab. GetCurSel (); Switch (Cursel) ... {Case 0:m_para1. ShowWindow (TRUE); M_para2. ShowWindow (FALSE); M_result. ShowWindow (FALSE); Break Case 1:m_para1. ShowWindow (FALSE); M_para2. ShowWindow (TRUE); M_result. ShowWindow (FALSE); Break Case 2:m_para1. ShowWindow (FALSE); M_para2. ShowWindow (FALSE); M_result. ShowWindow (TRUE); Break Default:; } *presult = 0;

10. Add a button under the Idd_mytab_dialog dialog box titled "Calculate" to add an event response function for it, the code is as follows:

?

1 2 3 4 M_para1. UpdateData (TRUE); M_para2. UpdateData (TRUE); M_result. Setresultvalue (m_para1. Getparavalue () +m_para2. Getparavalue ()); M_result. UpdateData (FALSE);

The above mentioned is not the full content of the question, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.