Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the best way to find position of a control relative to it's parent window?

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

like image 703
kobik Avatar asked Oct 19 '22 22:10

kobik


1 Answers

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.

like image 133
kobik Avatar answered Oct 23 '22 10:10

kobik