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

  • msnu

    Posted by Mah wari on 10/16/2014 01:06pm

    Hi I have a dialog which contains property sheet and this sheet has property pages. my dialog has pushlike radio button . now I am adding one more property page which has an editbox cotrol dynamically to property sheet. every thing added n show properly . Now when I am at my dynamically added page and click on the parent dialog's radio button then my application hung (seems like entered in infinite loop) and I have kill my app. pls suggest solution apporach.

    Reply
  • 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
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds