windows Win32/MFC 从客户端 rect 获取窗口 rect
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/140347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Win32/MFC Get window rect from client rect
提问by Mark Ingram
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(...)
回答by Shog9
You're probably thinking of AdjustWindowRectEx()
. Keep in mind, this is intended for use when creatinga window - there's no guarantee that it will produce an accurate set of window dimensions for an existing window; for that, use GetWindowRect()
.
你可能会想到AdjustWindowRectEx()
. 请记住,这是在创建窗口时使用的- 不能保证它会为现有窗口生成一组准确的窗口尺寸;为此,请使用GetWindowRect()
.
回答by Ken
Is this what you are looking for?
这是你想要的?
ClientToScreen
客户端到屏幕
http://msdn.microsoft.com/en-us/library/ms532670(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms532670(VS.85).aspx
回答by jussij
If you want to map client co-ordinates to window co-ordinates use the ClientToWindowAPI.
如果要将客户端坐标映射到窗口坐标,请使用ClientToWindowAPI。
If you want to map client co-ordinates to screen co-ordinates use the ClientToScreenAPI.
如果要将客户端坐标映射到屏幕坐标,请使用ClientToScreenAPI。
回答by aMarCruz
For control reposition use:
对于控制重新定位使用:
RECT client;
::SetRect(&client, 0, 0, 200, 200);
::MapWindowPoints(hwndControl, ::GetParent(hwndControl), (POINT*)&client, 2);
::SetWindowPos(...)