There are at-least 2 ways of doing this AFAIK.
How do I find position of a Win32 control/window relative to its parent window?
and this:
How to get size and location of a control placed on a dialog in MFC?
htext := GetDlgItem(hDlg, IDI_TEXT);
GetWindowRect(htext, R);
// (1)
// Pt := Point(R.Left, R.Top);
// ScreenToClient(hDlg, Pt);
// R := Rect(Pt.X, Pt.Y, Pt.X + R.Right - R.Left, Pt.Y + R.Bottom - R.Top);
// OR: (2)
MapWindowPoints(0, {GetParent(htext)} hDlg, R, 2);
FrameRect(dc, R, brush);
Which of the methods is better and why? Is the method with MapWindowPoints
will work with multiple monitors?
My concern is mainly with MapWindowPoints
and multi-monitors since passing 0
as hWndFrom
will use the HWND_DESKTOP
Since @TLama is refusing to take credit and post an answer I'll post one for him to finalize it. (Thanks! :))
The most obvious problem with method (1)
ScreenToClien
is that it fails if the Dialog window has the WS_EX_LAYOUTRTL
style and its content is mirrored.
In such case, Method (2)
MapWindowPoints
will correctly return mirrored point.
I could not find any other differences other than WS_EX_LAYOUTRTL
.
Both methods works just fine with multiple monitors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With