Creating a full application using the CPropertySheet
Posted
by Panagiotis Piperopoulos
on August 6th, 1998
I discovered recently that it is possible to create a full application using the CPropertySheet as the class for the main window of the application.
If you read the source of the small demo you will understand better what i mean.
I created a new class named CSheet that has CPropertySheet as the base class.
CSheet does have four member variables of type CPropertyPage, named: Page1, Page2, Page3 and Page4.
It also contains a CMenu variable.
When the CSheet constructor is called i am creating the four pages and i am adding them to the property sheet.
CSheet is overloading the virtual OnInitDialog function and in this function its doing two thinks.
1) Hides the property sheet buttons OK, CANCEL and APPLY.
2) Loads the applications menu.
BOOL OnInitDialog( )
{
CPropertySheet::OnInitDialog();
GetDlgItem( IDOK )->ShowWindow( SW_HIDE );
GetDlgItem( IDCANCEL )->ShowWindow( SW_HIDE );
GetDlgItem( ID_APPLY_NOW )->ShowWindow( SW_HIDE );
Menu.LoadMenu( IDR_MENU );
SetMenu( &Menu );
return TRUE;
}
CSheet does have a message map, which redirects the menu message to the display member function which displays the page selected.
BEGIN_MESSAGE_MAP( CSheet, CPropertySheet )
ON_COMMAND_RANGE( IDM_1, IDM_4, DisplayPage )
END_MESSAGE_MAP()
void DisplayPage( int Page )
{
switch( Page )
{
case IDM_1 :
SetActivePage( &Page1 );
break;
case IDM_2 :
SetActivePage( &Page2 );
break;
case IDM_3 :
SetActivePage( &Page3 );
break;
case IDM_4 :
SetActivePage( &Page4 );
break;
}
}
DECLARE_MESSAGE_MAP()
};
After defining the CSheet class, i am creating a CWinApp derived class that creates a CSheet Window as its main window and thats all.I have an application that is based on CPropertySheet as the main window class.
I hope that my code will help you.
May the SOURCE be with you.
Date Posted: 05/03/98

Comments
How to change this application to a wizard-like
Posted by Legacy on 04/02/2003 12:00amOriginally posted by: Egor
I tried SetWizardMode() and got an error.
Any suggestion would be appreciated.
ReplyWhen you add the menu, buttons get chopped off at bottom...
Posted by Legacy on 09/18/2002 12:00amOriginally posted by: Tam Bui
ReplyYour example was very useful!
Posted by Legacy on 12/08/2001 12:00amOriginally posted by: Antonio Ramirez
Thanks for your example, some times it is needed a small but compiled source code.
ReplyHow to add icon?
Posted by Legacy on 09/05/2001 12:00amOriginally posted by: hong
How to add an icon on the window title?
ReplyHow do you add a Minimize Button on the Caption Bar??
Posted by Legacy on 06/14/2001 12:00amOriginally posted by: HP
Could you tell me how do you add a Minimize button on the Caption Bar of this application?
Thank!
Reply
Preventing ENTER key from closing the dialog
Posted by Legacy on 03/27/2000 12:00amOriginally posted by: Ian Littlewood
Preventing this type of application from exiting when the ENTER key is pressed requires a different approach than with CDialog-derived applications.
When you hit ENTER inside this type of app, the framework first calls CPropertyPage::OnApply(). If CPropertyPage::OnApply() returns TRUE, then CPropertyPage::OnOK() is called. By this point, it's already too late to prevent the dialog-box from closing as the next call is to DestroyWindow().
What you have to do is provide an implementation for OnApply() in your CPropertyPage-derived class(es) and ensure that it always returns FALSE. This effectively prevents OnOK() from being called.
The downside is that clicks on the OK button are tricky -- easiest work-around is to hide the default OK button and provide your own.
You also may have to manually ghost your APPLY button as it will never ghost on it's own (OnApply() does return FALSE all the time, after-all!) :)
Hope someone finds this useful.
- Ian
ReplyThere is an app wizard for doing this
Posted by Legacy on 11/12/1999 12:00amOriginally posted by: Bogdan
Use the property sheet app wizard at
http://codeguru.developer.com/propertysheet/PropSheet_Wizard.shtml, and you'll have your application generated.
Reply
How to get notification on tab change/changing?
Posted by Legacy on 04/23/1999 12:00amOriginally posted by: Murray Bilker
I created a propertysheet application like this example
with no real problem. I can't seem to get an on_notify
message to let me know when the user has selected a new
property page. I am trying the OnSelChange and OnSelChanging
messages but apparently I'm doing something wrong.
Need help (other than mental).
Thanks,
Murray
Replydo it with AppWizard
Posted by Legacy on 04/09/1999 12:00amOriginally posted by: Konstantin Avdeev
I found that a pretty simple way to make an application that
is CPropertySheet based, is to create the DialogBased app with
AppWizard and then change some code (and add some of yours, of course)
in YourAppDlg.cpp and YourAppDlg.h.
That way you have CAboutDlg created for you by AppWizard and most of
the code in OnInitDialog() that handles icon drawing,
OnSysCommand() and OnQueryDragIcon(). I discarded OnPaint() immediately,
so I'm not sure if you can use it without changing or if you can use it at all.
You just have to change "CDialog" to "CPropertySheet" in most places,
change constructor and a bit of other code.
Reply