获取资源文件中定义的对话框大小 [英] Get Dialog Size as defined in resource file
本文介绍了获取资源文件中定义的对话框大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要确定资源文件中定义的对话框客户区的大小.
I need to determine the size of a dialog client area as defined in the resource file.
GetClientRect按桌面大小裁剪设计大小.我需要按屏幕单位设计的尺寸.我发现此旨在从对话框资源,但遗憾的是它使用MFC.
GetClientRect clips the design size by the size of the desktop. I need the size as designed in screen units. I found this which purports to retrieve the size form the dialog resource but sadly it uses MFC.
我打开了对话框,并显示了其HWND和ID.如何在不使用MFC的情况下以屏幕为单位获取dsign大小?
I have the dialog open and have its HWND and it's ID. How can I get the dsign size in screen units without using MFC stuff?
推荐答案
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;
}
这篇关于获取资源文件中定义的对话框大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文