Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I add controls (CButton) to a CPropertySheet?

Posted on 1997-01-15
1
Medium Priority
?
495 Views
Last Modified: 2013-11-20
I have a CProperySheet derived object to which I need to add four buttons.  I do not know how to do this, but I am trying to do the following in OnCreate:

int COptionSheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
#define BUTTON_WIDTH      50
#define BUTTON_HEIGHT      22
#define BUTTON_SPACE      10

if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
   return -1;

// TODO: Add your specialized creation code here
LPRECT lpRect;
// Get window size
GetWindowRect( lpRect );
// expand it by 150 to the right so I can add some boxes
// for statistics later
lpRect->right += 150;
// Resize the window
MoveWindow( lpRect );

// pAddButton is of type CButton * and is a public data member of COptionSheet
pAddButton = new CButton();
LPCTSTR lpszAddCaption = "Add";
CRect pAddRect;
// define a button size
pAddRect.left = 20;
pAddRect.right = pAddRect.left + BUTTON_WIDTH;
pAddRect.top = 360;
pAddRect.bottom = pAddRect.top + BUTTON_HEIGHT;                                                             
// create button
  BOOL bReturn = pAddButton->Create(lpszAddCaption,                                 WS_VISIBLE|BS_PUSHBUTTON,                                                       pAddRect, this, IDC_ADD_RADOBJECT);                        
}
Problems:
First I get an 0xC0000005 Access viloation when I call GetWindowRect( lpRect ); at the top of this function.

Second, how do I set the font of the text on my buttons to be the same as the default Ok/Cancel/Apply buttons on the CPropertySheet and what is the default text.

Is the method for adding other controls (static text, list box etc) the same as for adding a button?

Ed                                    
0
Comment
Question by:epeddyco
[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
1 Comment
 
LVL 1

Accepted Solution

by:
chedrick earned 200 total points
ID: 1300419
Here's the Access Violation problem...
LPRECT lpRect;    // This is the same as RECT *lpRect; Just a pointer, NO STORAGE. Probably pointer to NULL
// Get window size
GetWindowRect( lpRect );  //Tries to access NULL Pointer

Change this to
RECT aRect;
LPRECT lpRect=&aRect;
// Get window size
GetWindowRect( lpRect );
as an easy fix.

Second (sigh) Question:
Get the font used by the dialog (Get the CDC using GetDC(), then GetCurrentFont(...) ),  turn
off the font's bold attribute as follows:
Get a filled in LOGFONT structure via GetLogFont(...),
optionally adjust LOGFONT's lfWeight to 400, create a new CFont object initialize it using CreateFontIndirect with the LOGFONT structure
Select the font into the button's CDC by using SelectObject(...)
0

Featured Post

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.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…

715 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