C#获取窗口大小和位置坐标 GetWindowRect用法


[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);

[StructLayout(LayoutKind.Sequential)]
public struct RECT
        {
            public int Left; //最左坐标
            public int Top; //最上坐标
            public int Right; //最右坐标
            public int Bottom; //最下坐标
        }

//飞信示例:
RECT fx = new RECT();
GetWindowRect(h, ref fx);//h为窗口句柄
int width = fx.Right - fx.Left;                        //窗口的宽度
int height = fx.Bottom - fx.Top;                   //窗口的高度
int x = fx.Left;                                             
int y = fx.Top;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM