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?
Safai Ma
June 16th, 1999, 09:08 AM
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
Tom Labotka
June 21st, 1999, 03:01 PM
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.
Safai Ma
June 21st, 1999, 04:51 PM
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);
// 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.
// ....
}
-[i]Safai
Tom Labotka
June 23rd, 1999, 12:27 PM
I am making progress here. But I am getting an error. Here is the code:
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.
Safai Ma
June 23rd, 1999, 12:39 PM
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
Tom Labotka
June 25th, 1999, 10:10 AM
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
My question is, how do I position my other customer buttons? Do I modify rectOK? If so, how?
Safai Ma
June 25th, 1999, 02:44 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.