GetClientRect和GetWindowRect的区别

GetWindowRect() 得到的是在屏幕坐标系下的RECT(即以屏幕左上角为原点)

GetClientRect() 得到的是在客户区坐标系下的RECT(即以所在窗口,去掉了标题栏,左右下边框等之后的左上角为原点,仅仅是个大小,返回值的左上角永远为00

ScreenToClient() 就是把屏幕坐标系下的RECT坐标转换为客户区坐标系下的RECT坐标。 ClientToScreen反之。还有SetParent方法可以设置窗口间的关系,在c#中的调用如下:

public struct RECT

{

public int X1;

public int Y1;

public int X2;

public int Y2;

}

[DllImport("User32.dll")]

static extern IntPtr SetParent(IntPtr hWnd, IntPtr hParent);

[DllImport("user32.dll")]

public static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect);

[DllImport("user32.dll")]

public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);

原文地址:https://www.cnblogs.com/bear831204/p/1402372.html