Winapi 如何获取对话框中控件的宽度-高度
我创建了一个带有一些控件的对话框-Winapi 如何获取对话框中控件的宽度-高度,winapi,get,height,width,controls,Winapi,Get,Height,Width,Controls,我创建了一个带有一些控件的对话框- IDD_DIALOG_EFFECTS DIALOGEX 0, 0, 168, 49 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 400, 0, 0x1 BEGIN --- --- --- --- CTEXT "",3,200,120,60,60, WS_VISIBLE END 在头文件中: 常数int16 kIte
IDD_DIALOG_EFFECTS DIALOGEX 0, 0, 168, 49
STYLE DS_SETFONT | WS_CHILD
FONT 8, "MS Sans Serif", 400, 0, 0x1
BEGIN
--- ---
--- ---
CTEXT "",3,200,120,60,60, WS_VISIBLE
END
在头文件中:
常数int16 kItem=3
现在,当我试图得到控制的位置和尺寸时,它是不准确的
// Retrieving the location and dimension of the control
RECT wRect_proxy;
GetWindowRect(GetDlgItem(hDlg, kItem), &wRect_proxy);
ScreenToClient (hDlg, (LPPOINT)&wRect_proxy);
ScreenToClient (hDlg, (LPPOINT)&(wRect_proxy.right));
// Output of the control as location and position that I am getting is:
wRect_proxy.left: 300 (Expected: 200)
wRect_proxy.top: 195 (Expected: 120)
wRect_proxy.right: 390 (Expected: 60)
wRect_proxy.bottom: 293 (Expected: 60)
我需要计算控件的宽度-高度。寻求帮助…你得到的是控制的高度 RC文件使用对话框基本单位。 创建该对话框时,使用特定字体查找每个DLU包含多少像素 内部用于将RC文件中的值转换为最终像素数 在正确(0,0,4,8)上使用MapDialogrect可以获得1个DLU的基值 现在将x-width乘以4,然后除以刚才计算的“宽度”基本单位。对于y高度,乘以8,再除以 “高度”
这可以用MulDiv轻松完成。您收到的是控件的高度 RC文件使用对话框基本单位。 创建该对话框时,使用特定字体查找每个DLU包含多少像素 内部用于将RC文件中的值转换为最终像素数 在正确(0,0,4,8)上使用MapDialogrect可以获得1个DLU的基值 现在将x-width乘以4,然后除以刚才计算的“宽度”基本单位。对于y高度,乘以8,再除以 “高度” 这可以用MulDiv轻松完成。非常感谢……) 根据您的指导和建议,片段将是:
// Summarizing the code-snippet.
RECT wRect;
GetWindowRect(GetDlgItem(hDlg, kDProxyItem), &wRect);
ScreenToClient (hDlg, (LPPOINT)&wRect);
ScreenToClient (hDlg, (LPPOINT)&(wRect.right));
RECT pixel_rect;
pixel_rect.left = 0;
pixel_rect.top = 0;
pixel_rect.right = 4;
pixel_rect.bottom = 8;
bool b_check = MapDialogRect(hDlg, &pixel_rect);
LONG base_pix_width = pixel_rect.right;
LONG base_pix_height = pixel_rect.bottom;
// Calculating acctual X,Y coordinates with Width - Height of the Proxy Rectangle
RECT proxy_acc_dim;
proxy_acc_dim.left = (wRect.left * 4 / base_pix_width);
//or we can do the same by: MulDiv(wRect.left, 4, base_pix_width);
proxy_acc_dim.right = (wRect.right * 4 / base_pix_width) - proxy_acc_dim.left;
//or we can do the same by: MulDiv(wRect.right, 4, base_pix_width);
proxy_acc_dim.top = (wRect.top * 8 / base_pix_height);
//or we can do the same by: MulDiv(wRect.top, 8, base_pix_height);
proxy_acc_dim.bottom = (wRect.bottom * 8 / base_pix_height) - proxy_acc_dim.top;
//or we can do the same by: MulDiv(wRect.bottom, 8, base_pix_height);
proxy_acc_dim.left = proxy_rect.left;
proxy_acc_dim.top = proxy_rect.top;
proxy_acc_dim.right = proxy_rect.right - proxy_rect.left;
proxy_acc_dim.bottom = proxy_rect.bottom - proxy_rect.top;
它很好用。希望这对其他人有帮助……非常感谢……)
根据您的指导和建议,片段将是:
// Summarizing the code-snippet.
RECT wRect;
GetWindowRect(GetDlgItem(hDlg, kDProxyItem), &wRect);
ScreenToClient (hDlg, (LPPOINT)&wRect);
ScreenToClient (hDlg, (LPPOINT)&(wRect.right));
RECT pixel_rect;
pixel_rect.left = 0;
pixel_rect.top = 0;
pixel_rect.right = 4;
pixel_rect.bottom = 8;
bool b_check = MapDialogRect(hDlg, &pixel_rect);
LONG base_pix_width = pixel_rect.right;
LONG base_pix_height = pixel_rect.bottom;
// Calculating acctual X,Y coordinates with Width - Height of the Proxy Rectangle
RECT proxy_acc_dim;
proxy_acc_dim.left = (wRect.left * 4 / base_pix_width);
//or we can do the same by: MulDiv(wRect.left, 4, base_pix_width);
proxy_acc_dim.right = (wRect.right * 4 / base_pix_width) - proxy_acc_dim.left;
//or we can do the same by: MulDiv(wRect.right, 4, base_pix_width);
proxy_acc_dim.top = (wRect.top * 8 / base_pix_height);
//or we can do the same by: MulDiv(wRect.top, 8, base_pix_height);
proxy_acc_dim.bottom = (wRect.bottom * 8 / base_pix_height) - proxy_acc_dim.top;
//or we can do the same by: MulDiv(wRect.bottom, 8, base_pix_height);
proxy_acc_dim.left = proxy_rect.left;
proxy_acc_dim.top = proxy_rect.top;
proxy_acc_dim.right = proxy_rect.right - proxy_rect.left;
proxy_acc_dim.bottom = proxy_rect.bottom - proxy_rect.top;
它很好用。希望能对其他人有帮助