Adding a Button to CPropertySheet
Posted
by Jeremy Davis
on March 5th, 1999
- First sub-class CPropertySheet with a class of your own using ClassWizard, say CMyPropertySheet.
- Next in your MyPropertySheet.h add a member function CButton m_ButtonCopy. Also in your resource.h add a #define IDC_BUTTON_COPY 0x02000. where 0x02000 is a resource ID that has not been used yet.
- Then over-ride the CPropertySheet::OnInitDialog function and insert the following code...
CRect rect, tabrect;
int width;
//Get button sizes and positions
GetDlgItem(IDOK)->GetWindowRect(rect);
GetTabControl()->GetWindowRect(tabrect);
ScreenToClient(rect); ScreenToClient(tabrect);
//New button -> width, height and Y-coordiate of IDOK
// -> X-coordinate of tab control
width = rect.Width();
rect.left = tabrect.left; rect.right = tabrect.left + width;
//Create new "Add" button and set standard font
m_ButtonCopy.Create("Copy",
BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTON_COPY);
m_ButtonCopy.SetFont(GetFont());
If your were to compile at this point you would now see the new Copy
button in the CPropertySheet; however the button would not do anything. To handle a single
button click added the following line to your message map declaration...
BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet)
//{{AFX_MSG_MAP(CMyPropertySheet)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_COPY, OnButtonCopy)
END_MESSAGE_MAP()
Lastly add a helper function called OnButtonCopy() and insert your
code for when the button is clicked.
Date Last Updated: March 5, 1999

Comments
How to add Combo Box To the property sheet ?
Posted by babumohan on 10/10/2004 05:17am-
ReplyAdd Combobox
Posted by Jeremy Davis on 10/12/2004 05:42amWhen creating the combobox have you specified the expanded size? When displayed, the combobox will appear closed, but you must create it as if it were expanded. Look at www.codeproject.com for more help as it's much better than codeguru!
ReplyIs it possible to locate the button at other place in Propertysheet dialog??
Posted by Legacy on 04/09/2002 12:00amOriginally posted by: Santosh
In this sample, the button is added by taking tabcontrol's
x and y co-ordinates.
Is it possible to add it any where in the dialog??
ReplyCan it work in a modalless propertysheet
Posted by Legacy on 03/30/2002 12:00amOriginally posted by: hjzhai
Hi:
ReplyI read your work,it's great.And I tried to add a button to a modalless propertysheet,but failed.Would you like to give me some advice?
Thanks in advance!
how to add menu to a property sheet
Posted by Legacy on 03/10/2002 12:00amOriginally posted by: Gunjan Goel
hi,
can u tell me how to add a menu to a property sheet/property page.
it cld beadded to a dialog if the style was popup...
as soon as i made it Child the menu addition option became disabled.
pls. help
Replygunjan
How to add the button to the top of the sheet?
Posted by Legacy on 02/08/2002 12:00amOriginally posted by: sujith.s
How can i add the button to the top of a modeless propertysheet?ie. above the property page.
ReplyI have a solution to my previous Q.!!!!
Posted by Legacy on 04/09/2001 12:00amOriginally posted by: Ohad Redlish
contact me if u r interested:
ohadr@nice.com
and i will show you how to make the unvisible-buttons visible. since in Modeless style, the buttons are invisible, you have to FORCE the system show them.
Ohad
ReplypropertySheet and buttons
Posted by Legacy on 12/14/2000 12:00amOriginally posted by: Ohad
hi.
i read your advices. i think it's very nice, but how do i make the buttons in a PropertySheet visible, when the sheet is in Modeless style???
this is much much tougher!!!
please advise if you know anything
Replythanks,
Ohad R
SW engineer
NICE Systems
Israel
Help me on button in propertysheet
Posted by Legacy on 09/09/1999 12:00amOriginally posted by: Hanying chen
Hi, everyone
I just used this code. But the button can't work at all. I examed the code carefully, still don't know why. The only difference is my propertysheet is a modeless dialog.
Is it the reason?
Thanks
Hanying Chen
Reply99/9/9
Here's a little routine to set tab order of buttons...
Posted by Legacy on 03/16/1999 12:00amOriginally posted by: Chris Conn
BOOL SetTabOrder(BOOL bShowWindow, HWND hWndTop, ...)
{
ASSERT(hWndTop != NULL);
BOOL
bRtrn = FALSE;
UINT
uiFlags = SWP_NOMOVE | SWP_NOSIZE;
// Validate that something was sent in
if (hWndTop != NULL)
{
HWND
curHwnd = hWndTop,
prevHwnd = HWND_TOP;
// Add the show windows if needed
if (bShowWindow == TRUE)
uiFlags |= SWP_SHOWWINDOW;
va_list curArg;
va_start(curArg, curHwnd );
// Initialize variable arguments
// Additional parameters can be optional
while (curHwnd != NULL)
{
// Now add any additional windows into the tab order
bRtrn = ::SetWindowPos(curHwnd, prevHwnd, 0, 0, 0, 0, uiFlags);
// Keep track of the last windows handle
prevHwnd = curHwnd;
// Get the next argument
curHwnd = va_arg(curArg, HWND);
} // while (lpTmp != NULL)
va_end(curArg); // Reset variable arguments
} // End of check whether handle is valid
return bRtrn;
} // SetTabOrder()
I've used this successfully for several property sheets that I am currently using (and also dynamically changing by adding additional buttons or other controls). Here's the mechanism that I use to call this function:
SetTabOrder(TRUE, oNewButton1.GetSafeHwnd(),
Reply::GetDlgItem(this->GetSafeHwnd(), IDOK),
::GetDlgItem(this->GetSafeHwnd(), IDCANCEL),
::GetDlgItem(this->GetSafeHwnd(), ID_APPLY_NOW),
::GetDlgItem(this->GetSafeHwnd(), IDHELP),
oNewButton2.GetSafeHwnd(),
oNewButton3.GetSafeHwnd(),
oNewButton4.GetSafeHwnd(),
oNewButton5.GetSafeHwnd(),
NULL);
What about Tab order?
Posted by Legacy on 03/10/1999 12:00amOriginally posted by: Bill Foust
Thats a really nice bit of work there. It helped out a lot.
The one problem I see now is the tab order. It would be nice to be able to tab through the fields of the property page, then to the new button, then to OK, Cancel etc. Right now, you get the page then OK, Cancel, Tabs, and then the new button.
Also quick note, do the stuff in OnInitDialog as described AFTER calling the base class OnInitDialog. :) That was the first mistake I made. :)
Bill
Reply