Reputation: 49
I had created a dialog with some 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
In Header - file: const int16 kItem = 3;
Now when I am trying to get the position and dimension of the control, it's not accurate.
// 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)
I need to calculate width - height of the control. Seeking help ...
Upvotes: 0
Views: 173
Reputation: 49
Thanks a Ton ... :)
As per your guidance and suggestion the snippet will be:
// 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;
It works fine. Hope it would be help full to others ...
Upvotes: 0
Reputation: 15355
What you receive IS the height of the contro!
The RC file uses Dialog Base Units. When the Dialog is created the specific font is used to find howmany Pixels are 1 DLU.
Internally MapDalogRect is used to convert the values from the RC file to the final number of Pixels.
Using MapDialogrect on CRect(0,0,4,8) gives you the base values of 1 DLU.
Now take the x-width multiply with 4 and divide by the "width" base units you just calculated. For the y-height multiply with 8 and divide by the "height".
This can be easily done with MulDiv.
Upvotes: 5