How do I determine the coordinates of controls in a WM_INITDIALOG message?
I am having troubles to determine the (what I believe to be the) client coordinates
of a (radio button) control in the WM_INITDIALOG
message of a DlgProc
.
Here's what I try:
// Retrieve coordinates of Control with respect to the scre开发者_JAVA技巧en.
RECT rectOrthoButton;
GetWindowRect(GetDlgItem(hWnd, IDC_ORTHO), &rectOrthoButton);
// Translate coordinates to more useful coordinates: those that
// are used on the dialog.
// In order to do the translation we have to find the top left
// point (coordinates) of the dialog's client:
POINT dlgTopLeft;
ClientToScreen(hWnd, &dlgTopLeft);
// With these coordinates we can do the translation.
// We're only interested in top and left, so we skip
// bottom and right:
rectOrthoButton.top -= dlgTopLeft.y;
rectOrthoButton.left -= dlgTopLeft.x;
use_top_and_left(rectOrthoButton.top, rectOrthoButton.left);
I expected rectOrthoButton.top
and .left
to be the top left coordinates of my control with respect to the dialog's client area. It turns out they aren't and I am not sure
what they point to as rectOrthoButton.left
is equal to -40.
Edit: Now that I was directed to initialize the POINT with
POINT dlgTopLeft = {0, 0};
(which I stupidly forgot): Is there a shorter way to accomplish what I want?
To convert a Point to screen coordinates, the Point should contain the client coordinates (0, 0 in case of client origin) before passing to ClientToScreen
.
精彩评论