如何获得对话框中控件的宽度 - 高度

Sak*_*ket 0 height winapi controls get width

我创建了一个带有一些控件的对话框 -

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
Run Code Online (Sandbox Code Playgroud)

在Header中 - 文件:const 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)
Run Code Online (Sandbox Code Playgroud)

我需要计算控件的宽度 - 高度.寻求帮助......

xMR*_*MRi 5

你收到的是控制的高度!

RC文件使用Dialog Base Units.创建对话框时,使用特定字体查找多个像素是1 DLU.

内部MapDalogRect用于将RC文件中的值转换为最终的像素数.

在CRect(0,0,4,8)上使用MapDialogrect可以得到1 DLU的基值.

现在将x宽度乘以4并除以刚刚计算的"宽度"基本单位.对于y高度乘以8并除以"高度".

这可以通过MulDiv轻松完成.