Simple use of the tab Control

Source: Internet
Author: User

This article describes a simple example of adding a label to a normal dialog box.

In the first step, drag a tab control to the dialog box and add the variable m_tabctrl;

   

Step 2: Add two dialog boxes: Resource idd_dialog1, idd_dialog2, set style to child, border to none, and add corresponding cdialog m_page1, m_page2

Step 3 Add the following code in oninitdialog ()

  

 

 

Code

// Add a tab name
M_tabctl.insertitem (0, l "Tab 1 ");
M_tabctl.insertitem (1, l "Tab 2 ");

// Set idc_tab1 as the parent window
M_page1.create (idd_dialog1, getdlgitem (idc_tab1 ));
M_page2.create (idd_dialog2, getdlgitem (idc_tab1 ));

// Obtain the size of the idc_tabtest client Zone
Crect RC;
M_tabctl.getclientrect (& rc );

// Adjust the position of the subdialog box in the parent window
RC. Top + = 30;
RC. Bottom-= 8;
RC. Left + = 8;
RC. Right-= 8;

// Set the size of the subdialog box and move it to the specified position
M_page1.movewindow (& rc );
M_page2.movewindow (& rc );

// Hide and display
M_page1.showwindow (true );
M_page2.showwindow (false );

// Set the default Tab
M_tabctl.setcursel (0 );

 

 

Step 4 Add the tcn_selchange Event Response Function onselchangetabtest (nmhdr * pnmhdr, lresult * presult) of the tab control. The function body code is as follows:

 

Code

Void cpropagedlg: ontcnselchangetab1 (nmhdr * pnmhdr, lresult * presult)
{
// Todo: add the control notification handler generation here
Int cursel = m_tabctl.getcursel ();

Switch (cursel)
{
Case 0:
M_page1.showwindow (true );
M_page2.showwindow (false );
Break;
Case 1:
M_page1.showwindow (false );
M_page2.showwindow (true );
Break;
}
* Presult = 0;
}

 

Then adjust the appropriate position of the dialog box ....

 

 

 

Related Article

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.