MFC: paste the dialog box in the tab Control

Source: Internet
Author: User

1. First create a dialog box MFC ApplicationProgramIn the toolbox, place the tab Control in the appropriate position in the dialog box.

In the dialog box class, declare a ctabctrl variable:

Ctabctrl m_tab;

The m_tab variable is used to interact with the tab Control in the dialog box. Therefore, add the ddx_control statement to the dodataexchange function:

Ddx_control (PDX, idc_tab1, m_tab );

Idc_tab1 is the ID of the tab control.

2. Create two dialog box programs to serve as two tabs of the tab control. Don't forget to change style to child and border to none. Then you can add other controls.

Then create two classes for the two dialogs, such as cpage1 and cpage2.

Then, add the two dialog box objects to the dialog box header file. At the same time, a variable int m_curseltab is added to indicate which page is about to be switched.

Int m_curseltab;
Cpage1 m_page1;
Cpage2 m_page2;
Cdialog * pdialog [2]; // used to save the object pointer of the dialog box

In the initialization function of the dialog box class, you need to associate cpage1, cpage2, and Tab control, save the page address, and set the initial Page.

 
// Add two pages for tab Control
 
M_tab.insertitem (0, _ T ("Farm "));
 
M_tab.insertitem (1, _ T ("NOTE "));
 
 
// Create two dialog boxes
 
M_page1.create (idd_dialog1, & m_tab );
 
M_page2.create (idd_dialog2, & m_tab );
 
// Set the display range in the tab.
 
Crect RC;
 
M_tab.getclientrect (RC );
 
RC. Top + = 20;
 
RC. Bottom-= 0;
 
RC. Left + = 0;
 
RC. Right-= 0;
 
M_page1.movewindow (& rc );
 
M_page2.movewindow (& rc );
 
 
 
// Save the object pointer of the dialog box
 
Pdialog [0] = & m_page1;
 
Pdialog [1] = & m_page2;
 
// Display the initial Page
 
Pdialog [0]-> showwindow (sw_show );
 
Pdialog [1]-> showwindow (sw_hide );
 
// Save the current selection
 
M_curseltab = 0;

Here we use a cdialog pointer array to save each page of tab control. The size of the array is the number of tab control pages, the array subscript corresponds to the index of each page (this facilitates quick access ).

Next, add a message handler for tab control:

On_notify (tcn_selchange, idc_tab1, & ctabdlg: ontcnselchangetab1)

 
Void ctabdlg: ontcnselchangetab1 (nmhdr * pnmhdr, lresult * presult)
 
{
 
// Hide the current page
 
Pdialog [m_curseltab]-> showwindow (sw_hide );
 
// Get the new page index
 
M_curseltab = m_tab.getcursel ();
 
// Display the New Page
 
Pdialog [m_curseltab]-> showwindow (sw_show );
 
* Presult = 0;
 
}
 
 

3. If you want to obtain the data of the control in the internal dialog box outside the tab control, you need to use the DDX/DDV mechanism and call the corresponding updatedata function.

M_page1.updatedata ();
M_page2.updatedata ();

[Routine]
Http://dl.dbank.com/c0jgltk3t7

 

[Thank you for choosing this article]
Http://blog.csdn.net/hustspy1990/article/details/5425365

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.