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