-
May 17th, 2011, 12:06 PM
#1
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.
-
May 17th, 2011, 01:32 PM
#2
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.
--EJMW
-
May 17th, 2011, 02:57 PM
#3
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);
}
-
May 17th, 2011, 03:03 PM
#4
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.
--EJMW
-
May 17th, 2011, 03:16 PM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|