|
-
June 15th, 1999, 04:51 PM
#1
Buttons on property sheet
I have created several buttions on my property sheet and sample code is as follows:
m_calc.Create("&Calculate",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(149,339,224,364),this,WM_CALCULATE);
The problem is that when the program is loaded onto a computer with large fonts in the windows setting, the buttons are out of position. How can I correct this?
-
June 16th, 1999, 09:08 AM
#2
Re: Buttons on property sheet
If this button is always relative to some other button (like above or to the left of the OK button), then you can use the coordinates of the OK button as a guide to position (and size) your Calc button. That is what I did when I put my status bar into the property sheet.
The other way, although I don't recommend it, is to use different position (and size) for each different font size you are going to support. This will break when a user is using a font size that you don't support.
-Safai
-
June 21st, 1999, 03:01 PM
#3
Re: Buttons on property sheet
That sounds like it might work. However, it is modeless propertysheet and only has custom buttons. Could I use the size of the propertysheet as the guide? How would I do that? Please supply example code if possible.
Thanks.
-
June 21st, 1999, 04:51 PM
#4
Re: Buttons on property sheet
First of all, all the standard buttons are still there, they are just disabled an hidden by default. You can use Spy++ to verify this. That's why you can still use them as a guide. Like always make your custom button the same size as the OK button, or twice the width of the OK button. All you need to do isBOOL CYourPropertySheet::OnInitDialog()
{
CPropertySheet::OnInitDialog();
CWnd *pWnd = GetDlgItem(IDOK);
CRect rectOK;
if (pWnd) // just in case
{
pWnd->GetWindowRect(&rectOK);
}
ScreenToClient(&rectOK);
int btnHeight = rectOK.Height();
// If you want to show the default buttons, you have to resize the property sheet
CRect rect;
GetWindowRect(&rect);
SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height() + btnHeight + 10, SWP_NOMOVE|SWP_NOZORDER);
int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP };
for (int i=0; i<sizeof(ids)/sizeof(int); i++)
{
CWnd *btn = GetDlgItem(ids[i]);
ASSERT(btn != NULL);
// modeless property sheet has no default buttons
// (they are disabled and in-visible by default)
btn->ShowWindow(SW_SHOW);
btn->EnableWindow();
// move the buttons down a bit
btn->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(0, btnHeight + 10);
btn->MoveWindow(&rect);
}
// now you got the position and size of the OK button.
// and you can position your custom buttons.
// ....
}
-Safai
-
June 23rd, 1999, 12:27 PM
#5
Re: Buttons on property sheet
I am making progress here. But I am getting an error. Here is the code:
CRect rect;
GetWindowRect(&rect);
SetWindowPos(NULL,0,0,rect.Width(),rect.Height()+btnHeight+10,SWP_NOMOVE|SWP_NOZORDER);
int ids[]={IDOK,IDCANCEL,ID_APPLY_NOW,IDHELP};
for(int i=0;i<sizeof(ids)/sizeof(int);i++)
{
CWnd *btn=GetDlgItem(ids);
ASSERT(btn !=NULL);
btn->ShowWindow(SW_SHOW);
btn->EnableWindow();
btn->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(0,btnHeight+10);
btn->MoveWindow(&rect);
}
However, the error I get states "class CWnd *__thiscall CWnd::GetDlgItem(int) const' : cannot convert parameter 1 from 'int [4]' to 'int' "
How do I correct this?
Thanks again. You've been a big help.
-
June 23rd, 1999, 12:39 PM
#6
Re: Buttons on property sheet
I'm sorry, the "Markup" this board support mess it up. You see my ids[ i] is treated as italics...
It should be
CWnd *btn=GetDlgItem(ids [ i ]);
ASSERT(btn !=NULL);
btn->ShowWindow(SW_SHOW);
-Safai
-
June 25th, 1999, 10:10 AM
#7
Re: Buttons on property sheet
Ok, I got this to run. You will have to forgive me by asking so many questions. I have no formal training and am just learning this. I got my Calculate button to appear where it should by using
m_calc.Create("&Calculate",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CALCULATE);
My question is, how do I position my other customer buttons? Do I modify rectOK? If so, how?
-
June 25th, 1999, 02:44 PM
#8
Re: Buttons on property sheet
Yep. Here is the code to position a button to the right of the OK button.
m_calc.Create("&Calculate",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CALCULATE);
rectOK.OffsetRect((rectOK.Width() + 10 /* gap between two controls */), 0);
m_custom1.Create("&custom1",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CUSTOM1);
rectOK.OffsetRect((rectOK.Width() + 10 /* gap between two controls */), 0);
m_custom2.Create("&custom2",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CUSTOM2);
To put it on the left,m_calc.Create("&Calculate",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CALCULATE);
rectOK.OffsetRect(-(rectOK.Width() + 10 /* gap between two controls */), 0);
m_custom1.Create("&custom1",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CUSTOM1);
rectOK.OffsetRect(-(rectOK.Width() + 10 /* gap between two controls */), 0);
m_custom2.Create("&custom2",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,CRect(&rectOK),this,WM_CUSTOM2);
You may want to experiment with the 10 pixel gap between two controls. By the way, most people will use IDC_CALCULATE as control ID.
-Safai
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|