How do I determine the coordinates of controls in a WM_INITDIALOG message?

Posted by René Nyffenegger on Stack Overflow See other posts from Stack Overflow or by René Nyffenegger
Published on 2010-12-30T00:49:23Z Indexed on 2010/12/30 0:54 UTC
Read the original article Hit count: 110

Filed under:

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 screen.
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.

© Stack Overflow or respective owner

Related posts about winapi