,,,
Tab control - . , "" .
MFC Tab control - CTabCtrl.
, CTabCtrl "" - .
:
1) tab_control .
2) Tab Control ID = IDC_TAB.
3) ClassWizard, - CTabCtrl Control.
4) OnInitDialog CTabCtrl.
5) ClassWizard, Tab control '.
6) .
, m_ctrTab CTabCtrl. BOOL CTab_controlDlg::OnInitDialog() :
...
TC_ITEM TabItem;
TabItem.mask = TCIF_TEXT;
TabItem.pszText = "1";
m_ctrTab.InsertItem( 0, &TabItem );
TabItem.pszText = "2";
m_ctrTab.InsertItem( 1, &TabItem );
TabItem.pszText = "3";
m_ctrTab.InsertItem( 2, &TabItem );
...
Tab Control, . , , , . - - Tab Control' - , .
. - CDialog. CPage1, CPage2 CPage3( Page1.cpp(h), Page2.cpp(h), Page3.cpp(h) ) .
Style "Child" Border "none" - , ( , Static Text ), .
tab_controlDlg.cpp
#include "Page1.h"
#include "Page2.h"
#include "Page3.h"
OnInitDialog:
, m_ctrTab !!! lParam TCITEM . pPage1, pPage2 pPage3 - ! ShowWindow() - , .
...
CPage1* pPage1;
pPage1 = new CPage1;
TabItem.mask = TCIF_PARAM;
TabItem.lParam = (LPARAM)pPage1;
m_ctrTab.SetItem(0, &TabItem);
VERIFY(pPage1->Create(CPage1::IDD, &m_ctrTab));
pPage1->SetWindowPos(NULL, 10, 30, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
pPage1->ShowWindow(SW_SHOW);
CPage2* pPage2;
pPage2 = new CPage2;
TabItem.mask = TCIF_PARAM;
TabItem.lParam = (LPARAM)pPage2;
m_ctrTab.SetItem(1, &TabItem);
VERIFY(pPage1->Create(CPage2::IDD, &m_ctrTab));
pPage2->SetWindowPos(NULL, 10, 30, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
pPage2->ShowWindow(SW_HIDE);
CPage3* pPage3;
pPage3 = new CPage3;
TabItem.mask = TCIF_PARAM;
TabItem.lParam = (LPARAM)pPage3;
m_ctrTab.SetItem(2, &TabItem);
VERIFY(pPage1->Create(CPage3::IDD, &m_ctrTab));
pPage3->SetWindowPos(NULL, 10, 30, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
pPage3->ShowWindow(SW_HIDE);
...
. TCN_SELCHANGE TCN_SELCHANGING :
void CTab_controlDlg::OnSelchangingTab(NMHDR* pNMHDR, LRESULT* pResult) {
// TODO: Add your control notification handler code here
int nTab = m_ctrTab.GetCurSel();
TC_ITEM tci;
tci.mask = TCIF_PARAM;
m_ctrTab.GetItem(nTab, &tci);
ASSERT(tci.lParam);
CWnd* pWnd = (CWnd *)tci.lParam;
pWnd->ShowWindow(SW_HIDE);
*pResult = 0;
}
void CTab_controlDlg::OnSelchangingTab(NMHDR* pNMHDR, LRESULT* pResult) {
int nTab = m_ctrTab.GetCurSel();
TC_ITEM tci;
tci.mask = TCIF_PARAM;
m_ctrTab.GetItem(nTab, &tci);
ASSERT(tci.lParam);
CWnd* pWnd = (CWnd *)tci.lParam;
pWnd->ShowWindow(SW_HIDE);
*pResult = 0;
}
, OnInitDialog
.
OnDestroy:
void CTab_controlDlg::OnDestroy() {
CDialog::OnDestroy();
CWnd* pWnd;
TC_ITEM tci;
tci.mask = TCIF_PARAM;
for (int i = 2; i>=0; i--) {
m_ctrTab.GetItem(i, &tci);
ASSERT(tci.lParam);
pWnd = (CWnd *)tci.lParam;
pWnd->DestroyWindow();
delete pWnd;
}
}
, .
Copyright (c) 2025 Stud-Baza.ru , , , .