I know I can use MoveWindow to move it but I only want to move the button on the x axis. Thanks.
A:
I figured it out. You can get the button's (screen) position using GetWindowRect, then you can use ScreenToClient to get it's location in the form. Example:
RECT buttonScreenRect;
GetWindowRect(hwnd, &buttonScreenRect);
POINT buttonClientPoint;
buttonClientPoint.x = buttonScreenRect.left;
buttonClientPoint.y = buttonScreenRect.top;
ScreenToClient(hwnd, &buttonClientPoint);
MoveWindow(hwnd, 50, buttonClientPoint.y, buttonScreenRect.right - buttonScreenRect.left, buttonScreenRect.bottom - buttonScreenRect.top);
Hope it helps!
Grant
2010-08-09 00:04:01
You should update your question to reflect what you actually wanted to ask. There is no way anyone could have figured out your real problem was "how do I translate from screen to client coordinates" from your initial question.
jeffamaphone
2010-08-09 00:09:48