Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add a Control to a Modless Propertysheet

Posted on 2000-05-10
7
Medium Priority
?
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

597 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