Search code examples
c++tabsmfccpropertysheet

How to properly change tabs on CPropertySheet


I have a CPropertySheet with three tabs. I have a different CPropertyPage class for each tab. When my CPropertySheet is loaded with the debugger, the first page is always shown correctly. However, when I click on any of the other tabs, the CPropertyPage area becomes blank. Even if I click back on the first tab, the area is still empty. I am using Visual Studio, MFC, C++.

I am trying to find the proper way to handle the different tab clicks and have my tabs show correctly. This is the code to initialize my property sheet and it's pages:

BOOL CSLIMOptCplusplusApp::InitInstance()
{
CWinApp::InitInstance();
SQLHENV m_1;
EnvGetHandle(m_1);

Login lgn;   //Creates a Login dialog for the user to enter credentials.
lgn.DoModal();

CImageSheet*      imagedlg = new CImageSheet( "Admin Options" );
CImageDisplay*    pageImageDisplay    = new CImageDisplay;
CImageDimensions* pageImageDimensions = new CImageDimensions;
ListOption*       pageListOption      = new ListOption;

ASSERT( imagedlg );
ASSERT( pageImageDisplay );
ASSERT( pageImageDimensions );  
ASSERT( pageListOption );

imagedlg->AddPage( pageListOption);
imagedlg->AddPage( pageImageDisplay );
imagedlg->AddPage( pageImageDimensions );

imagedlg->m_psh.dwFlags |= PSH_NOAPPLYNOW;  //Removes the default Apply button
imagedlg->Create();
imagedlg->ShowWindow( SW_SHOW );
m_pMainWnd = imagedlg;

This is the code for my CPropertySheet class:

BOOL CImageSheet::OnInitDialog()
{
CWnd* pOKButton = GetDlgItem( IDOK );
ASSERT( pOKButton );
pOKButton->ShowWindow( SW_HIDE );

CWnd* pCANCELButton = GetDlgItem( IDCANCEL );
ASSERT( pCANCELButton );
pCANCELButton->ShowWindow( SW_HIDE );

// Set Flags for property sheet
m_bModeless    =  TRUE;
m_nFlags      |=  WF_CONTINUEMODAL;


BOOL bResult   = CPropertySheet::OnInitDialog();
m_bModeless    =  FALSE;
m_nFlags      &=  ~WF_CONTINUEMODAL;

//Get button sizes and positions
CRect rect, tabrect;
GetDlgItem( IDOK )->GetWindowRect( rect );
GetTabControl()->GetWindowRect( tabrect );

ScreenToClient( rect );
ScreenToClient( tabrect );  

UpdateData( FALSE );

Solution

  • My problem was that I was setting m_bModeless to false,

    BOOL bResult   = CPropertySheet::OnInitDialog();
    m_bModeless    =  FALSE;  //Change to TRUE to fix the problem.
    m_nFlags      &=  ~WF_CONTINUEMODAL;