Update: Creating a full application using the CPropertySheet

Download Source Code and Example


In reaction about my article 'Creating a full application using the CPropertySheet' someone mailed me and asked to add an icon and a minimize button to the PropertySheet window. Adding the icon is the easy task.

Adding the minimize button was the difficult part, it needs very litle code,
but the way it is done is the interesting part.
We cant just overload the PrecreateWindow() and change the window style.
We must do the style changing when OnInitDialog() Event happens and we must change the application's system menu in order to make the minimize button to work.

The code below should be very easy to understand for some one that have read my previous example.

class CSheet : public CPropertySheet
{
public:
	
	CPropertyPage Page1;
	CPropertyPage Page2;
	CPropertyPage Page3;
	CPropertyPage Page4;
	CMenu  Menu;

	CSheet() : CPropertySheet( "CPropertySheet By Piperopoulos Panagiotis" )
	{
		Page1.Construct( IDD_VIEW1 );
		Page2.Construct( IDD_VIEW2 );
		Page3.Construct( IDD_VIEW3 );
		Page4.Construct( IDD_VIEW4 );
		AddPage( &Page1 );
		AddPage( &Page2 );
		AddPage( &Page3 );
		AddPage( &Page4 );
	}

	~CSheet(){}

	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 );

		// NEW LINES START

		// Load the app icons
		SetIcon( AfxGetApp()->LoadIcon( IDI_ICONS ), FALSE );
		SetIcon( AfxGetApp()->LoadIcon( IDI_ICONB ), TRUE );

		// add the minimize button to the window
		::SetWindowLong( m_hWnd, GWL_STYLE, GetStyle() | WS_MINIMIZEBOX );
		
		// add the minimize command to the system menu
		GetSystemMenu( FALSE )->InsertMenu( -1, MF_BYPOSITION | MF_STRING,
					   SC_ICON, "Minimize" );

		// activate the new sysmenu
		DrawMenuBar();
		
		// NEW LINES END

		return TRUE;
	}
	
	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()
};

BEGIN_MESSAGE_MAP( CSheet, CPropertySheet )
	ON_COMMAND_RANGE( IDM_1, IDM_4, DisplayPage )
END_MESSAGE_MAP()


class TheApp : public CWinApp
{
public:
	
	TheApp(){}
	~TheApp(){}

	virtual BOOL InitInstance()
	{
	#ifdef _AFXDLL
		Enable3dControls();		
	#else
		Enable3dControlsStatic();
	#endif

	CSheet ps;
	m_pMainWnd = &ps;
	ps.DoModal();

	return FALSE;
	}
};

Last updated: 21 July 1998



Comments

  • Why doesnt F1 help work ?

    Posted by Mike Pliam on 10/06/2008 03:05pm

    F1 help won't work using this method. If one selects the HTML Help option in the Wizard, a dialog-based app is created wherein F1 will summon HTML help. Once the original dialog-based application is converted to a CPropertySheet derived application, F1 no longer works and pressing it results in the message 'Failed to launch help.' Any idea how to get this to work?

    Reply
  • Really great!

    Posted by Legacy on 07/26/2003 12:00am

    Originally posted by: Ramesh

    Was struggling for a whole day to get a minimize button on a property sheet application.

    Saved my another day.

    Thanks a lot.

    Reply
  • setwindowlong is not working in property page - help pls

    Posted by Legacy on 06/26/2002 12:00am

    Originally posted by: soni

    i want to create a simple propertypage with validations:

    i created a propertysheet and 3 propertypages
    the property pages are created using dialog resource derived fro cpropertypage.

    now i did addpage in property sheet

    next i handled onkillactive and ok events of property page.

    In onkillactive, i am doing validations and in case of error i want the focus to reman on the same page. For thta i have to do
    SetWindowLong correct?

    I am using pure mfc, not sdk. The control is not remaining in the same page. what shouls i do? can u send me a simple sample app of propertypages with validations?

    Reply
  • VeryGood

    Posted by Legacy on 01/17/2002 12:00am

    Originally posted by: limj

    very good , i just meet the same question in my work.

    Reply
  • How about other languages?

    Posted by Legacy on 11/10/2000 12:00am

    Originally posted by: Andreas J�ger

    You add some entries to the systems menu. But what about other languages? I cannot add "Minimize" or "Restore" to a german menu... It is very ugly. Do you have a solution for this (difficult) task?

    Thanks

    Andreas Jaeger

    Reply
  • Accessing Data at the Property Sheet Level

    Posted by Legacy on 09/06/2000 12:00am

    Originally posted by: Jim Brown

    I am trying to build an application using only the property sheet interface. I am able to get the application built to the point that it displays the property sheets in the tabbed dialog box as it should.

    The problem I am having is:

    I want all the property pages (tabs) to have access to the same object. This object should be created at the property sheet "level". The property pages could then set the properties of the object and call methods of the object and display the object data in edit controls on the property page.

    I can not seem to find a way for the property pages to be able to access an object created at the property sheet level.

    Any suggestions on how to pull this off?

    Thanks!

    Reply
  • How do you do this same task, accept using a modeless PropertySheet?

    Posted by Legacy on 03/22/2000 12:00am

    Originally posted by: Ellen Lay

    In the interest of letting a user use your propert sheet application multiple times before it quits, how could you use a modeless propertysheet to do this. Inquiring minds are dying to know.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • On-demand Event Event Date: October 23, 2014 Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this webcast to learn why physical appliances are preferable to virtual backup appliances, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds