Knowledge Base Nr: 00145 tabcontrol.cpp - http://www.swe-kaiser.de

Downloads:

MFC: Tabbed Dialog mit PropertySheet und PropertyPages

  
Resourceneditor:
================
Insert Dialog IDD_PROP_PAGES_xxx
Controls einfügen

ClassWizard:
============
Add Class: New IDD: IDD_PROP_PAGE_xxx base class: CPropertyPage
Add Class: New base class: CPropertySheet

Code:
=====
//in App-Klasse header includieren
#include "ProPage1.h"
#include "PropPage2.h"
#include "PropPage3.h"

//member oder static variablen anlegen:
CMyPropertySheet* g_dlgPS;
CProPage1* g_pp1a;
CProPage1* g_pp1b;//CPropPage2 pp2;
CPropPage3* g_pp3;

BOOL CTabdlg1App::InitInstance()
{
...
//dialoge anlegen...
g_pp1a = new CProPage1();
g_pp1b = new CProPage1();
g_pp3 = new CPropPage3();

g_dlgPS = new CPropertySheet("Simple PropertySheet");
//...und einfügen
g_dlgPS->AddPage(g_pp1a);
g_dlgPS->AddPage(g_pp1b);
g_dlgPS->AddPage(g_pp3);

m_pMainWnd = g_dlgPS;

//originaldialog ignorieren stattdessen unser PropertySheet aufschalten
int nResponse = g_dlgPS->DoModal(); //dlg.DoModal();
if (nResponse == IDOK)
{
...
}

//zugriff auf die einzelnen dialoge
void CTabdlg1App::DoAction()
{
g_pp1a->GetDlgItem(IDC_EDIT1)->SetWindowText("page1");
g_pp1b->GetDlgItem(IDC_EDIT1)->SetWindowText("page2");
//ACHTUNG: bug oder feature?!
//wenn der dialog noch nie angewählt wurde gehts schief!!!
//also: fenster prüfen!
CWnd pWnd = g_pp3->GetDlgItem(IDC_EDIT1);
if (pWnd)
pWnd->SetWindowText("page3");

g_dlgPS->SetActivePage(1);
}

//in dialogklassen funktionen in der app-klasse aufrufen
void CPropPage3::OnButton1()
{
CTabdlg1App* pApp = (CTabdlg1App*)AfxGetApp();

pApp->DoAction();
}

The code below will hide the OK button. The IDs of the standard buttons are IDOK, IDCANCEL, IDHELP and ID_APPLY_NOW.

CWnd *pWnd = GetDlgItem( IDOK );
pWnd->ShowWindow( FALSE );