Discussion:
MapWindowPoints SetWindowPos/MoveWindow problem
(too old to reply)
Dan
2003-07-10 16:41:29 UTC
Permalink
Why is it when I execute this code, the (X,Y) coordinates are
different between block 1 and block 3 when pWnd is any control with a
border around it? Helk, I'm not even moving the control! However, if
the border style is turned off, the problem goes away. Is the border
considered in the call to GetClientRect()? This also happens with
static controls as well.

// block 1 (Get position of edit control in parent dialog)
pWnd->GetClientRect(&rect);
pWnd->MapWindowPoints(pParentWnd, &rect);

// block 2 (Stay in same place)
pWnd->MoveWindow(&rect); // or SetWindowPos()

// block 3 (Shows different values than block 1!!)
pWnd->GetClientRect(&rect);
pWnd->MapWindowPoints(pParentWnd, &rect);
Jugoslav Dujic
2003-07-11 07:56:20 UTC
Permalink
Dan wrote:
| Why is it when I execute this code, the (X,Y) coordinates are
| different between block 1 and block 3 when pWnd is any control with a
| border around it? Helk, I'm not even moving the control! However, if
| the border style is turned off, the problem goes away. Is the border
| considered in the call to GetClientRect()? This also happens with
| static controls as well.

GetClientRect always returns (0,0) for the top-left corner. Thus,
it is expected that your control will be offset by (two) border widths
using your code:

| // block 1 (Get position of edit control in parent dialog)
| pWnd->GetClientRect(&rect);
| pWnd->MapWindowPoints(pParentWnd, &rect);
|
| // block 2 (Stay in same place)
| pWnd->MoveWindow(&rect); // or SetWindowPos()
|
| // block 3 (Shows different values than block 1!!)
| pWnd->GetClientRect(&rect);
| pWnd->MapWindowPoints(pParentWnd, &rect);

Instead, you need:

pWnd->GetWindowRect(&rect);
pParentWnd->ScreenToClient(&rect);

// block 2 (Stay in same place)
pWnd->MoveWindow(&rect); // or SetWindowPos()

// block 3 (Shows SAME values as block 1!!)
pWnd->GetWindowRect(&rect);
pParentWnd->ScreenToClient(&rect);
--
Jugoslav
___________
www.geocities.com/jdujic
Loading...