1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
SIZE GetDialogSize(INT nResourceId, BOOL bApproximateCalcMethod = FALSE, LPCTSTR strDllName = NULL)
{
SIZE dlgSize = {0};
HINSTANCE hModule = 0;
if(strDllName != NULL)
hModule= ::LoadLibrary(strDllName);
else
hModule = ::GetModuleHandle(NULL);
HRSRC hRsrc = ::FindResource(hModule, MAKEINTRESOURCE(nResourceId), RT_DIALOG);
HGLOBAL hTemplate = ::LoadResource(hModule, hRsrc);
DLGTEMPLATE* pTemplate = (DLGTEMPLATE*)::LockResource(hTemplate);
if (bApproximateCalcMethod) // the approximate method of calculating
{
LONG dlgBaseUnits = GetDialogBaseUnits();
int baseunitX = LOWORD(dlgBaseUnits), baseunitY = HIWORD(dlgBaseUnits);
dlgSize.cx = MulDiv(pTemplate->cx, baseunitX, 4);
dlgSize.cy = MulDiv(pTemplate->cy, baseunitY, 8);
}
else // the accurate method of calculation
{
HWND hDlg = ::CreateDialogIndirect(0, pTemplate, NULL, DialogProc);
RECT rc = {0};
::GetWindowRect(hDlg, &rc);
::DestroyWindow(hDlg);
dlgSize.cx = rc.right - rc.left;
dlgSize.cy = rc.bottom - rc.top;
}
UnlockResource(hTemplate);
::FreeResource(hTemplate);
if(strDllName != NULL)
::FreeLibrary(hModule);
return dlgSize;
}
| |