Adding a Control to the Property Sheet

Each property page has its own set of controls. The only control that they share are the standard button in the property sheet itself. If you want to add an edit control, a preview button or any other control, you have to do it at run time. The code below shows you how to add an edit control.

Step 1: Derive your own class from CPropertySheet

We cannot use the CPropertySheet class directly, since we need to add a member variable. If you aren't already using a sub-class of CPropertySheet then derive one.

Step 2: Add member variable

Add member variable to the CPropertySheet derived class. The edit control will be created and accessed using this member.
public:
	CEdit m_edit;

Step 3: Create the edit control in OnInitDialog

Override the OnInitDialog() function and add the code to create the edit control to this function. It is a good idea to call the base class version of the function before doing anything specific for the derived class.

The property sheet is first resized to accommodate the new edit control. The edit control is then created at the desired location. The WS_EX_CLIENTEDGE gives it a 3-D look. The edit control is created with a different font than used by other control. We fix this by a call to SetFont() and set the font to be the same as the property sheet.

The text value in the edit control can be set or retrieved using the m_edit object.

BOOL CMyPropSheet::OnInitDialog()
{
	BOOL bResult = CPropertySheet::OnInitDialog();

	CRect rectWnd;
	GetWindowRect(rectWnd);
	SetWindowPos(NULL, 0, 0,
		rectWnd.Width() + 100,
		rectWnd.Height(),
		SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

	m_edit.CreateEx( WS_EX_CLIENTEDGE, _T("EDIT"), NULL,
				WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, 
				rectWnd.Width(), 20, 80, 24, m_hWnd, 0, 0 );

	m_edit.SetFont( GetFont() );
	
	CenterWindow();
	return bResult;
}



Comments

  • how to enforce focus on dlg item of another page

    Posted by Legacy on 02/24/2004 12:00am

    Originally posted by: Stephan Geue

    I wrote a property sheet with some edit fields and combo boxes on one page. I don't want the user to leave this page by choosing another page or apply or OK if the data of these items are not plausible. I can catch the application killing the focus on these items but I cannot prevent it from leaving the page or the sheet at all. Moreover, if I issue a message "data not correct" on KILLFOCUS, this happens even then, if the user wants to cancel the whole sheet. Do you know a solution?
    Thanks in advance.
    Stephan

    Reply
  • Adding Connect to Server dialog box on MMC Snapin using Visual Basic Designer

    Posted by Legacy on 08/09/2002 12:00am

    Originally posted by: Amish Shah

    Hello,

    I was wondering if anyone knew how to add the "Connect to Server" property page that comes up when, for example, one clicks on the Computer Management node or other nodes. I am trying to create a customized MMC snapin and I am looking for some help as to how to add on the "Connect to Server" dialog box when the user adds the MMC snapin. I am also using the Visual Basic designer. Any help is much appreciated. Thank you.

    Amish Shah

    Reply
  • Initializing Pages with value in Registry(like Properties)

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

    Originally posted by: Rider

    Hi:

    I am trying to create a property sheet with 3-4 pages for setting options. (just like the ones you get right click desktop, then properties).

    My problem is: HOW and where do I initialize the pages with the previous stored values (they are in registry and i can retrieve them).

    For example, say the value in memory is 20. i have 4 radio buttons with titles 5, 10, 20, 40. I want the "20" button checked when the pages first shows. There after, that page will show whatever the user clicked just before switching pages.

    Thanx

    Reply
  • add control to the top or to the bottom?

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

    Originally posted by: ofirc

    i am trying to add control to the top of the propertysheet in the same method but i get a strange propertysheet,
    any idea?

    Reply
  • Controls in Property Page doesnt work

    Posted by Legacy on 03/15/2002 12:00am

    Originally posted by: Jemin n shingala

    Re sir i have embedde property sheet int the dialog, using CPropertySheet in OninintDialog, Now the Probs, is i have a button in Property page, on whose click, event i want many actions on the dialog, say display of Message Box, but when i have BN_CLICKED event for that button and put my code, the application hangs, plz suggest me some solutions, fast waiting eagerly for reply

    Reply
  • How to add Scroll bar to PropertySheet as well as in PropertyPages?

    Posted by Legacy on 03/14/2002 12:00am

    Originally posted by: G.Paramaguru

    I have enabled Scroll bar using EnableScrollBarCtrl function of PropertyPage but it is difficult to activate it, I cant move the pages up and down.I have even tried out by calling OnVScroll function of respective page and sheet, but iam unable to achieve it. Kindly help me out my problem.

    Thanks,
    regards
    G.Paramaguru,

    Reply
  • How to use the "Help button" in propertysheet ??

    Posted by Legacy on 02/19/2002 12:00am

    Originally posted by: ted

    I set 
    
    propsheet.m_psh.dwFlags |= PSH_HASHELP;
    to enable the Help button in propertysheet,but I cann't use this Help button. Could somenoe tell me how to "highlight" Help button that I can press the Help button. thanks!

    Reply
  • property sheet problem

    Posted by Legacy on 09/03/2001 12:00am

    Originally posted by: Vilas kulkarni

    How to add button to property sheet which is created dynamically
    

    Reply
  • How to add control when propert sheet si dynamically created

    Posted by Legacy on 08/31/2001 12:00am

    Originally posted by: Fawaz

    Hi
    
    Thanks for such useful information.
    I have to add one more button to the already set of standard buttons.
    My property sheet is dynamically created.
    There is no OnInitDialog function.
    Where should i put the code and also i get assertion at

    GetWindowRect(rectWnd);

    I have a derived class already.

    IMPLEMENT_DYNAMIC(CPSProcessOptions, CPropertySheet)

    It seems that i need to pass in the parent window somehow because rectWnd is empty.
    I commented the OnInitDialog line as it was giving me assertion at that also.
    I tried to put the code in the domodal function of the derived class and the constructor.
    I didn't get any errors but the same assertions.
    Do i need to derive another class and then do this in there?
    Can you pl. let me know.
    thanks
    Fawaz

    Reply
  • Status Bar

    Posted by Legacy on 08/22/2001 12:00am

    Originally posted by: karin

    How can I add a status bar in a property sheet ???

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this webcast that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base application that will jumpstart you into building your own more complex app …

  • Targeted attacks and advanced threats are customized to infiltrate your unique IT infrastructure, evade conventional defenses, and remain hidden while stealing your corporate data. To detect these criminal intrusions, analysts and security experts agree that organizations should deploy advanced threat protection as part of an expanded security monitoring strategy. For this comparative analysis of breach detection systems, product analysis reports and comparative analysis reports are used to create the security …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds