Re: How to get dialog size?
On 9 Apr., 08:22, "Mihai N." <nmihai_year_2...@yahoo.com> wrote:
The conversion depends on screen resolution and
user preference control panel settings.
The formula is simple:
http://support.microsoft.com/kb/125681
The screen resolution affects the result of GetTextMetrics
and GetTextExtentPoint32.
The font settigns in Control Panel matter only if the dialog
template does not fully specify a font.
Oops, that is new to me. For converting dialog units
to pixels on screen I use the functions below. It seems to
work, but since I am not very sure I'd like to show it for
discussion:
int MapDialogUnitX(int nX, CWnd* pWnd)
{
ASSERT(::IsWindow(pWnd->GetSafeHwnd()));
CRect rect(0, 0, nX, 0);
if (MapDialogRect(pWnd->GetSafeHwnd(), &rect))
nX = rect.right;
else
{
TRACE("MapDialogUnitX: GetLastError returned %d.\n",
GetLastError());
HDC hDC = GetDC(pWnd->GetSafeHwnd());
nX = nX*5/3*GetDeviceCaps(hDC, LOGPIXELSX)/96;
ReleaseDC(pWnd->GetSafeHwnd(), hDC);
}
return nX;
}
int MapDialogUnitY(int nY, CWnd* pWnd)
{
ASSERT(::IsWindow(pWnd->GetSafeHwnd()));
CRect rect(0, 0, 0, nY);
if (MapDialogRect(pWnd->GetSafeHwnd(), &rect))
nY = rect.bottom;
else
{
TRACE("MapDialogUnitY: GetLastError returned %d.\n",
GetLastError());
HDC hDC = GetDC(pWnd->GetSafeHwnd());
nY = nY*5/3*GetDeviceCaps(hDC, LOGPIXELSY)/96;
ReleaseDC(pWnd->GetSafeHwnd(), hDC);
}
return nY;
}