c#知道窗口句柄,如何获取窗口大小
来源:百度知道 编辑:UC知道 时间:2024/05/28 04:34:28
111
不记得有替代函数 ,你还是用 GetWindowRect吧
// 引用
using System.Runtime.InteropServices;
// 获得窗口矩形
[DllImport("user32.dll")]
public static extern int GetWindowRect(IntPtr hWnd, out RECT lpRect);
// 获得客户区矩形
[DllImport("user32.dll")]
public static extern int GetClientRect(IntPtr hWnd, out RECT lpRect);
// 矩形结构
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
int left;
int top;
int right;
int bottom;
}
// 调用
IntPtr hwnd = .....; // 窗口句柄
RECT rc;
GetWindowRect(hwnd, out rc);
GetClientRect(hwnd, out rc);
Form aa = Form.FromHandle("你的句柄");
int width = aa.Width;
int height = aa.Height;
Rectangle bb= aa.RectangleToClient();
Rectangle cc = aa.Rectangle