First, create a new MFC project, named Tabctrl, selected based on the dialog box, and then point to complete.
Second, remove the default added three controls on the dialog box, add a Tab Control controls, property settings: ID: IDC_TAB1
Third, the variable is bound controls Tab Control controls, a variable named m_Tab, type CTabCtrl.
Fourth, in TabCtrlDlg.cpp file, find the OnInitDialog initialization function and add the following code inside:
// columns, divided into the first page of the second page
m_Tab.InsertItem (0, _T ( "first page"));
m_Tab.InsertItem (. 1, _T ( "the second page"));
Fifth, add two dialog resource in the resource box inside,
The first dialog box:
Added by default on the Delete dialog box three controls; property settings: border is set to None; style is set to child, ID is IDD_PAGE1; add static text, the words "first page"; and then to add the corresponding class based on CDialog CPage1.
Second dialog box:
Delete the default dialog box to add three controls; property settings: border is set to None; style is set to child, ID is IDD_PAGE2; add static text, the words "second page"; add the corresponding class based on CDialog CPage2.
Sixth, in TabCtrlDlg.h include the header file and add two member variables m_Page1, m_ Page 2, as follows:
#include "Page1.h"
#include "Page1.h"
CPage1 m_Page1;
CPage2 m_Page2;
Seven, in the initialization function OnInitDialog TabCtrlDlg.cpp dialog box, add the following code inside:
// Associate dialog box, and IDC_TABTEST control to the parent window
m_Page1.Create (IDD_PAGE1, GetDlgItem (IDC_TAB1));
m_Page2.Create (IDD_PAGE2, GetDlgItem (IDC_TAB1));
// get the size of the client area IDC_TABTEST
CRect rs;
m_tab. the GetClientRect (& RS);
// adjust the position of the parent child dialog window
rs.top + = 30;
rs.bottom- = 60;
rs.left + =. 1;
rs.right- = 2;
// size settings dialog sub and moves to the specified position
m_Page1.MoveWindow (& RS);
m_Low Page a2.MoveWindow (& RS);
// hides are provided, and a display
m_Low Page 1.ShowWindow (to true);
m_Low Page 2.ShowWindow (to false);
// set default tab
m_Tab.SetCurSel (0);
Eight, select the Tab Control controls, right-click / add an event handler, message type TCN_SELCHANGE, incident response function OnSelchangeTabtest (NMHDR * pNMHDR, LRESULT * pResult),
Body function code is as follows:
int CurSel = m_Tab.GetCurSel();
switch(CurSel)
{
case 0:
m_Page1.ShowWindow(true);
m_ Page2.ShowWindow(false);
break;
case 1:
m_Page1.ShowWindow(true);
m_ Page2.ShowWindow(false);
break;
default:
;
}
* Director = 0;}