News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How can I create a property sheet with menubar and minimize button?

By Daniel Strigl, July 17, 2003.
Print version

Question

I am using a property sheet (CPropertySheet) in my dialog based MFC application. How can I create a property sheet with accessible menubar and minimize button?

Sample application

Answer

The answer is not very difficult. Just create your own class derived from CPropertySheet.

class CMyPropertySheet : public CPropertySheet { ... }

Inside the OnInitDialog message handler remove (hide) the OK button, so that the minimze button will be visible and create your menubar. When you have created your menubar you can load your toolbar from the application resources.

BOOL CMyPropertySheet::OnInitDialog() { BOOL bResult = CPropertySheet::OnInitDialog(); // TODO: Add your specialized code here // Remove (hide) the OK button SHDoneButton(m_hWnd, SHDB_HIDE); // Create the command bar control m_pWndEmptyCB = new CCeCommandBar; ASSERT_VALID(m_pWndEmptyCB); if (m_pWndEmptyCB != NULL) { m_pWndEmptyCB->CreateEx(this); ASSERT(::IsWindow(m_pWndEmptyCB->m_hWnd)); // Load the toolbar CCeCommandBar* pCommandBar = (CCeCommandBar*) m_pWndEmptyCB; ASSERT_VALID(pCommandBar); pCommandBar->LoadToolBar(IDR_OK_CANCEL); pCommandBar->SetSizes(CSize(83 + 7, 16 + 6), CSize(83, 16)); } return bResult; }

After that you can add some message handlers for your menubar buttons.

BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet) //{{AFX_MSG_MAP(CMyPropertySheet) ON_COMMAND(ID_OK, OnOk) ON_COMMAND(ID_CANCEL, OnCancel) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CMyPropertySheet::OnOk() { // TODO: Add your command handler code here if (GetActivePage()->UpdateData()) { m_bOkToClose = TRUE; EndDialog(IDOK); } } void CMyPropertySheet::OnCancel() { // TODO: Add your command handler code here m_bOkToClose = TRUE; EndDialog(IDCANCEL); }

Don't forget that the normal MFC implementation of CPropertySheet doesn't work with the transcriber. So, for more information about this problem and how to fix it just take a look at the following article: QA: Why does not CPropertySheet work with transcriber?

Sample application

You can download a sample application that illustrates a property sheet with minimize button and menubar.

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House