From: http://hi.baidu.com/moxingfen/blog/item/7576ec1263992258f819b8eb.html
Http://hi.baidu.com/moxingfen/blog/item/0d12a6f03481c8a6a40f52eb.html/cmtid/85efe86d6e59e1f7431694d5
Create an MFC project and draw a tabcontrol in your own window. Then, associate the control with the variable of the previous control, called m_page.
// Add an item to the tab_control
M_page.insertitem (0, _ T ("page1 "));
M_page.insertitem (1, _ T ("page2 "));
M_page.insertitem (2, _ T ("page3 "));
This is to add tags to it.
Then, insert a resource in the dialog box and set the following attributes to the Resource:
Border: None
Style: Child
Create a class for this dialog box. Cpage1 ..
Then add the following in the header file of the main window:
# Include "page1.h"
In the code file header of the Main Window, add:
Cpage1 m_page1;
Then write in the oninitdialog process of loading the main window:
M_page1.create (idd_page1, & m_page );
M_page1.setwindowpos (null, 10, 30,400,100, swp_showwindow );
In this way, this subwindow appears on the main window.
Right-click tabcontrol and choose add event handler. In the class list, select the class in the main window. The message type will not change. Start with your own name.
Void cmaindlg: ontcnselchange_page (nmhdr * pnmhdr, lresult * presult)
{
// Get current POS
Crect R;
M_page.getclientrect (& R );
// Which one is selected now?
Switch (m_page.getcursel ())
{
Case 0:
M_page1.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_showwindow );
Break;
Case 1:
M_page1.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_hidewindow );
Break;
Case 2:
M_page1.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_hidewindow );
Break;
}
* Presult = 0;
}
Of course, you can open an array, store the pointer of the dialog box object, and then you don't need to write the switch.