#include "PgGeneral.h"
#include "PgSettings.h"
#include "PgActivityLog.h"
Now, locate the
InitInstance() function, and near the bottom of it, replace the key start-up sequence as follows:
// replace these lines
// CMyProgDlg dlg;
// m_pMainWnd = &dlg;
// INT_PTR nResponse = dlg.DoModal();
// ... with these
CPropertySheet cSheet( L"WonderProg" );
CPgGeneral cPgGeneral;
CPgSettings cPgSettings;
CPgActivityLog cPgActivityLog;
cSheet.AddPage( &cPgGeneral );
cSheet.AddPage( &cPgSettings );
cSheet.AddPage( &cPgActivityLog );
int nResponse= cSheet.DoModal(); // run your entire program
if (nResponse == IDOK)
... etc...
You now have a program that has a PropertySheet as its main window. You can delete the two files MyProgDlg.cpp and MyProgDlg.h and you can remove the resource IDD_MYPROG_DIALOG
BOOL CSheetMain::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
//----------------- Some setup for the PropertySheet buttons
GetDlgItem(IDHELP)->ShowWindow(SW_HIDE); // so wonderful, no help is needed!
//----------------- move the two remaining buttons to the right
CRect rcBtn, rcDlg;
GetWindowRect( &rcDlg );
CButton* pBtn= (CButton*)GetDlgItem( IDCANCEL );
pBtn->GetWindowRect( &rcBtn );
ScreenToClient( &rcBtn );
int nOffset= (rcDlg.Width()-12)- rcBtn.right;
rcBtn.OffsetRect(nOffset,0);
pBtn->MoveWindow( &rcBtn, TRUE /*fRepaint*/ );
pBtn= (CButton*)GetDlgItem( IDOK );
pBtn->GetWindowRect( &rcBtn );
ScreenToClient( &rcBtn );
rcBtn.OffsetRect(nOffset,0);
pBtn->MoveWindow( &rcBtn, TRUE /*fRepaint*/ );
return bResult;
}
And modify your constructor to be:
CSheetMain::CSheetMain(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
m_psh.dwFlags |= PSH_NOAPPLYNOW ;
m_psh.dwFlags &= ~PSH_HASHELP;
}
#include "SheetMain.h" // at the top and...
...
// ...in InitInstance()
CSheetMain cSheet( L"WonderProg" );
//CPropertySheet cSheet( L"WonderProg" );
CSheetMain::CSheetMain(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
HICON hIcon= AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_psh.hIcon= hIcon;
m_psh.dwFlags |= PSH_NOAPPLYNOW |PSH_USEHICON ;
m_psh.dwFlags &= ~PSH_HASHELP;
}
That gives your program an icon to display on the title bar and in the taskbar when it's minimized. Now to enable the Minimize/Restore functionality, add this code to the bottom of your
CSheetMain::OnInitDialog() CMenu* pSysMenu = GetSystemMenu( FALSE );
pSysMenu->AppendMenu(MF_STRING, SC_MINIMIZE , L"Minimize");
pSysMenu->AppendMenu(MF_STRING, SC_RESTORE , L"Restore");
ModifyStyle( 0, WS_MINIMIZEBOX );
The finished product is illustrated by
Fig 1.1 at the top of this article.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)