How to get a control position?
So I want to move a control from a dialog box to some position and then move it back to it's initial position but, how do I get it's initial position? I tried ScreenToClient, MapWindowPoints, etc with no sucess. The first movement I know how to do, its going to be at the dialog's .left and .top.
Thanks.
Re: How to get a control position?
Call GetWindowRect() on your control to get its bounding rectangle in screen coordinates, then call ScreenToClient() on that rect from your dialog to translate into dialog coordinates.
Re: How to get a control position?
I already tried that, this code makes the first movement right, but the last one that's supposed to take it back to the initial spot takes it to the top left corner of the dialog.
Code:
RECT rc, rc2;
POINT p;
GetClientRect(hPic, &rc);
GetWindowRect(hPic, &rc2);
int width = rc.right - rc.left, height = rc.bottom - rc.top;
p.x=rc2.left;
p.y=rc2.top;
ScreenToClient(hPic, &p);
if(something){
MoveWindow(hPic, rc.left+4, rc.top+4, width, height, 1);
}
else if(something{
MoveWindow(hPic, p.x, p.y, width, height, 1);
}
Re: How to get a control position?
Code:
ScreenToClient(hPic, &p);
As I said, you need to call ScreenToClient from your dialog. You're calling it with the handle of your control.
Re-reading my post, I realize that wasn't very clear...sorry about that.
Re: How to get a control position?
Thank you, and I realized that it was my mistake, it was a function which the first movement would overwrite the position.