Solved

Add a Control to a Modless Propertysheet

Posted on 2000-05-10
7
314 Views
Last Modified: 2013-11-20
I have created a modless propertysheet by calling Create() on my CPropertySheet derived object. What do I need to do to add controls to the lower part below the propertypages? I would like to add a few buttons and a combobox.
0
Comment
Question by:awd
  • 4
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
mnewton022700 earned 200 total points
Comment Utility
You need to add these in the OnInitDialog method of your CPropertySheet derived class.

Actually, you might want to add the buttons in the OnCreate method and then move them in the OnInitialUpdate. This will make the TAB order better.

Here's some code to add a reset button to the page.

In the header file of your CPropertySheet class add a member variable "CButton m_resetButton"

In the cpp file:

const int BUTTON_HEIGHT = 20;
const int BUTTON_WIDTH = 60;
const int SPACE_BELOW_BUTTONS = 6;
const int SPACE_BETWEEN_BUTTONS = 5;
const int SPACE_RIGHT_OF_BUTTONS = 6;

int MyPropSheet::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
      BOOL retval = CPropertySheet::OnCreate(lpCreateStruct);

      m_resetButton.Create(buttonText,
            WS_CHILD | WS_VISIBLE |      WS_TABSTOP | BS_PUSHBUTTON,
            CRect(0,0,0,0),
            this,
            IDC_RESET_BUTTON);

      return(retval);
}

BOOL MyPropSheet::OnInitDialog()
{
      BOOL retval = CPropertySheet::OnInitDialog();

      CRect windowRect;
      this->GetWindowRect(&windowRect);

      // Resize this dialog to make room for buttons.

      windowRect.bottom += (BUTTON_HEIGHT + SPACE_BELOW_BUTTONS);
      this->SetWindowPos(NULL, 0, 0,
            windowRect.Width(), windowRect.Height(),
            SWP_NOZORDER | SWP_NOACTIVATE);

      this->ScreenToClient(&windowRect);
      CRect buttonRect((windowRect.right - (BUTTON_WIDTH + SPACE_RIGHT_OF_BUTTONS)),
            (windowRect.bottom - (SPACE_BELOW_BUTTONS + BUTTON_HEIGHT)),
            (windowRect.right - SPACE_RIGHT_OF_BUTTONS),
            (windowRect.bottom - SPACE_BELOW_BUTTONS));

      resetButton.MoveWindow(&buttonRect);

      return(retval);
}
0
 
LVL 3

Expert Comment

by:mnewton022700
Comment Utility
Another hint is that you might want to set the font of the button.

To do this I added another member variable to the property sheet: "CFont m_buttonFont"

In OnInitDialog I create this font as follows:

            LOGFONT logFont;
            CFont * pFont = this->GetTabControl()->GetFont();
            pFont->GetLogFont(&logFont);

            m_buttonFont().CreateFontIndirect(&logFont);

And then set the font of the button like this:

m_resetButton.SetFont(&m_buttonFont);
0
 
LVL 1

Expert Comment

by:ch_vasu
Comment Utility
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;
}

 
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:awd
Comment Utility
mnewton,

your sample code looks good. I have one question. When you create the button, why do you use the CRect(0, 0, 0, 0)? What effect will this have?
0
 
LVL 1

Author Comment

by:awd
Comment Utility
It looks like mnewton attempted an answer first.
0
 
LVL 1

Author Comment

by:awd
Comment Utility
mnewton,

Nevermind the last question. I see that you create it with the CRect(0,0,0,0) in the OnCreate and then Move it in the OnInitDialog. The button does not show up though. Any thoughts?
0
 
LVL 1

Author Comment

by:awd
Comment Utility
Thanks for the well written answer. It looks like the main problem I was having was leaving out the ScreenToClient call. You also gave me some ideas on improving the style of my code. I think the font suggestion will be helpful too.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now