Win32/MFC Get window rect from client rect

徘徊边缘 提交于 2020-01-15 08:27:07

问题


I know there is a function somewhere that will accept a client rect and it will convert it into a window rect for you. I just can't find / remember it!

Does anyone know what it is?

It will do something similar to:

const CRect client(0, 0, 200, 200);
const CRect window = ClientRectToWindowRect(client);
SetWindowPos(...)

回答1:


You're probably thinking of AdjustWindowRectEx(). Keep in mind, this is intended for use when creating a window - there's no guarantee that it will produce an accurate set of window dimensions for an existing window; for that, use GetWindowRect().




回答2:


Is this what you are looking for?

ClientToScreen

http://msdn.microsoft.com/en-us/library/ms532670(VS.85).aspx




回答3:


If you want to map client co-ordinates to window co-ordinates use the ClientToWindow API.

If you want to map client co-ordinates to screen co-ordinates use the ClientToScreen API.




回答4:


For control reposition use:

RECT client;
::SetRect(&client, 0, 0, 200, 200);
::MapWindowPoints(hwndControl, ::GetParent(hwndControl), (POINT*)&client, 2);
::SetWindowPos(...)


来源:https://stackoverflow.com/questions/140347/win32-mfc-get-window-rect-from-client-rect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!