Scaling vs Font setting
From: Balboos (balboos_at_masonicbrother.com.No.Spam)
Date: 03/05/04
- Next message: Nils: "Re: Exceptions and MFC"
- Previous message: TheBasilisk: "Socket and Retrieving Info"
- Next in thread: Johan Rosengren: "Re: Scaling vs Font setting"
- Reply: Johan Rosengren: "Re: Scaling vs Font setting"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 05 Mar 2004 14:53:08 GMT
Hi,
I had a nice scaling routine (code below), used to convert a dialog from
it's design time resolution to the current screen resolution, as full
screen. Then I discovered, quite accidentally, that if I changed the
windows font selection group from 'small fonts' to 'large fonts', it
scaled incorrectly, running off the screen in both directions.
Is there a cure for this?
Balboos
void CScaleDialog::RescaleWindow(CWnd *pDlg, int x0, int y0, int x, int y) {
// This method uses predefined x/y coorordinates for the scaling. The
initial
// values are the design-time resolution (x0, y0), while the new screen
// resolution is put into (x, y). Leaving out x and/or y triggers the
default
// mechanism, which get the current screen resolution. There is a handler
// for the ComboBox, which has two sets of dimension (normal, dropped).
// Steven S. Miller Feb 26,
2004
int xNew, yNew; // new dimensions of the control
// Use values from constructor, if available
if(x0<=0) x0 = designHres;
if(y0<=0) y0 = designVres;
// Get current screen resolution 'on the fly'
if(x<=0 || y<=0) { // handle 'defaults' (or errors?)
x = runHres = GetSystemMetrics(SM_CXSCREEN);
y = runVres = GetSystemMetrics(SM_CYSCREEN);
} // end: if(x<=0 || y<=0)
// Get scaling factors (ration of current:design resolution).
xScale = (double)x/(double)x0;
yScale = (double)y/(double)y0;
// A handle to the child window(s) - each control is a window
CWnd *pDlgItem = pDlg->GetWindow(GW_CHILD);
while(pDlgItem) {
if(pDlgItem->GetSafeHwnd() != NULL) { /* resize it */
tagRECT rCombo;
CRuntimeClass *rtc = pDlgItem->GetRuntimeClass();
// unsigned di = pDlgItem->GetDlgCtrlID();
pDlgItem->GetWindowPlacement(&r0); // we are assuming this is
properly scaled!
if(!stricmp(rtc->m_lpszClassName, "CComboBox")) { // special
handler for combo box
((CComboBox *)pDlgItem)->GetDroppedControlRect(&rCombo);
r0.rcNormalPosition.bottom = rCombo.bottom;
} // end: if(!stricmp(rtc->m_lpszClassName, "CComboBox"))
// Get New height, width
xNew = r0.rcNormalPosition.right - r0.rcNormalPosition.left;
yNew = r0.rcNormalPosition.bottom - r0.rcNormalPosition.top;
r.rcNormalPosition.left =
(int)(r0.rcNormalPosition.left*xScale); // x shift
r.rcNormalPosition.top =
(int)(r0.rcNormalPosition.top*yScale); // y shift
r.rcNormalPosition.right = r.rcNormalPosition.left +
(int)(xNew*xScale); // x scale
r.rcNormalPosition.bottom = r.rcNormalPosition.top +
(int)(yNew*yScale); // y scale
pDlgItem->SetWindowPlacement(&r); // we are assuming this is
properly scaled!
// Continue looping through controls
pDlgItem = pDlgItem->GetNextWindow();
} // end: if(pDlgItem->GetSafeHwnd() != NULL)
} // end: while(pDlgItem)
return;
} // void RescaleWindow(CWnd *pDlg, int x0, int y0, int x, int y)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * */
- Next message: Nils: "Re: Exceptions and MFC"
- Previous message: TheBasilisk: "Socket and Retrieving Info"
- Next in thread: Johan Rosengren: "Re: Scaling vs Font setting"
- Reply: Johan Rosengren: "Re: Scaling vs Font setting"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|