Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Add a Control to a Modless Propertysheet

Posted on 2000-05-10
7
Medium Priority
?
375 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 800 total points
ID: 2797977
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
ID: 2797988
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
ID: 2799537
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:awd
ID: 2800486
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
ID: 2800495
It looks like mnewton attempted an answer first.
0
 
LVL 1

Author Comment

by:awd
ID: 2800702
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
ID: 2800779
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

579 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