简体   繁体   English

Win32/MFC 从客户端 rect 获取窗口 rect

[英]Win32/MFC Get window rect from client rect

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(...)

You're probably thinking of AdjustWindowRectEx() .您可能正在考虑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() .为此,请使用GetWindowRect()

Is this what you are looking for?这是你想要的?

ClientToScreen客户端到屏幕

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

If you want to map client co-ordinates to window co-ordinates use the ClientToWindow API.如果要将客户端坐标映射到窗口坐标,请使用ClientToWindow API。

If you want to map client co-ordinates to screen co-ordinates use the ClientToScreen API.如果要将客户端坐标映射到屏幕坐标,请使用ClientToScreen API。

For control reposition use:对于控制重新定位使用:

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

This will give you window rect in client coordinates, so you can use rect(top,left) as offset这将为您提供客户端坐标中的窗口矩形,因此您可以使用 rect(top,left) 作为偏移量

CRect rectFrame;
GetWindowRect(&rectFrame);
ScreenToClient(&rectFrame);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM