这是我在google上搜CTabCtrl找到的,看人家的回答,多有职业精神。 网址: http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_10302200.html1. Create your dialog resource including the list and the tab control and add a picture control with id IDC_STATIC_DUMMY of wanted size and position of the child dialogs within the tab control and remove the 'Visible' style.2. Create the three child dialogs with style 'Child', no border and no caption.3. Create classes for these dialogs, e.g. CTabDlg, CMyDlg1, CMyDlg2, CMyDlg3.4. In CTabDlg do following: -add a CTabCtrl member for the tab control with ClassWizard, i.e. m_tab// In header file CTabDlg.h #include "MyDlg1.h" #include "MyDlg2.h" #include "MyDlg3.h"class CTabDlg... { ... CMyDlg1* m_pDlg1; CMyDlg2* m_pDlg2; CMyDlg3* m_pDlg3;void ShowChild( int id ); .... }// In implementation file CTabDlg.cpp // Override OnInitialUpdate() BOOL CTabDlg::OnInitDialog() { CDialog::OnInitDialog();
// create new dialogs m_pDlg1 = new CMyDlg1; m_pDlg2 = new CMyDlg2; m_pDlg3 = new CMyDlg3;m_pDlg1->Create( CMyDlg1::IDD, this ); m_pDlg2->Create( CMyDlg2::IDD, this ); m_pDlg3->Create( CMyDlg3::IDD, this );// position childs CRect rect; GetDlgItem( IDC_STATIC_DUMMY )->GetWindowRect( rect ); ScreenToClient( rect );m_pDlg1->MoveWindow( rect ); m_pDlg2->MoveWindow( rect ); m_pDlg3->MoveWindow( rect );// insert tab control items m_tab.InsertItem( 0, "Dialog 1" ); m_tab.InsertItem( 1, "Dialog 2" ); m_tab.InsertItem( 2, "Dialog 3" );ShowChild( 0 ); return TRUE; }void CTabDlg::ShowChild( int id ) { m_pDlg1->ShowWindow( ( id == 0 ) ? SW_SHOW : SW_HIDE ); m_pDlg2->ShowWindow( ( id == 1 ) ? SW_SHOW : SW_HIDE ); m_pDlg3->ShowWindow( ( id == 2 ) ? SW_SHOW : SW_HIDE ); }// add TCN_SELCHANGE notification message handler with ClassWizard void CTabDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult) { int id = m_tab.GetCurSel();ShowChild( id );*pResult = 0; }// cleanup BOOL CTabDlg::DestroyWindow() { m_pDlg1->DestroyWindow(); delete m_pDlg1; m_pDlg2->DestroyWindow(); delete m_pDlg2; m_pDlg3->DestroyWindow(); delete m_pDlg3;return CDialog::DestroyWindow(); }handle child dialog's data exchange within overriden CTabDlg::OnOK() ...
{
//TODO:Handle your control for different tab pages.
if(m_tabCtrl.GetCurSel == 0)
{
//xxx.Create();
}
else if(... == 1)
...
}
网址:
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_10302200.html1. Create your dialog resource including the list and the tab control and add a picture control with id IDC_STATIC_DUMMY of wanted size and position of the child dialogs within the tab control and remove the 'Visible' style.2. Create the three child dialogs with style 'Child', no border and no caption.3. Create classes for these dialogs, e.g. CTabDlg, CMyDlg1, CMyDlg2, CMyDlg3.4. In CTabDlg do following:
-add a CTabCtrl member for the tab control with ClassWizard, i.e. m_tab// In header file CTabDlg.h
#include "MyDlg1.h"
#include "MyDlg2.h"
#include "MyDlg3.h"class CTabDlg...
{
...
CMyDlg1* m_pDlg1;
CMyDlg2* m_pDlg2;
CMyDlg3* m_pDlg3;void ShowChild( int id );
....
}// In implementation file CTabDlg.cpp
// Override OnInitialUpdate()
BOOL CTabDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// create new dialogs
m_pDlg1 = new CMyDlg1;
m_pDlg2 = new CMyDlg2;
m_pDlg3 = new CMyDlg3;m_pDlg1->Create( CMyDlg1::IDD, this );
m_pDlg2->Create( CMyDlg2::IDD, this );
m_pDlg3->Create( CMyDlg3::IDD, this );// position childs
CRect rect;
GetDlgItem( IDC_STATIC_DUMMY )->GetWindowRect( rect );
ScreenToClient( rect );m_pDlg1->MoveWindow( rect );
m_pDlg2->MoveWindow( rect );
m_pDlg3->MoveWindow( rect );// insert tab control items
m_tab.InsertItem( 0, "Dialog 1" );
m_tab.InsertItem( 1, "Dialog 2" );
m_tab.InsertItem( 2, "Dialog 3" );ShowChild( 0 );
return TRUE;
}void CTabDlg::ShowChild( int id )
{
m_pDlg1->ShowWindow( ( id == 0 ) ? SW_SHOW : SW_HIDE );
m_pDlg2->ShowWindow( ( id == 1 ) ? SW_SHOW : SW_HIDE );
m_pDlg3->ShowWindow( ( id == 2 ) ? SW_SHOW : SW_HIDE );
}// add TCN_SELCHANGE notification message handler with ClassWizard
void CTabDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
int id = m_tab.GetCurSel();ShowChild( id );*pResult = 0;
}// cleanup
BOOL CTabDlg::DestroyWindow()
{
m_pDlg1->DestroyWindow();
delete m_pDlg1;
m_pDlg2->DestroyWindow();
delete m_pDlg2;
m_pDlg3->DestroyWindow();
delete m_pDlg3;return CDialog::DestroyWindow();
}handle child dialog's data exchange within overriden CTabDlg::OnOK() ...