Getting Active Window Coordinates and Height Width in C#

前端 未结 2 1720
醉话见心
醉话见心 2021-02-10 10:04

I just check in some of the posts here, but none were helpful to me.

The thing I am trying to do is to run a background process of Screen Capturing. Now I want a piece

2条回答
  •  悲&欢浪女
    2021-02-10 10:19

    [DllImport("user32.dll")]  
    static extern IntPtr GetForegroundWindow();  
    
    
    private IntPtr GetActiveWindow()  
    {  
        IntPtr handle = IntPtr.Zero;  
        return GetForegroundWindow();  
    }
    

    Then get the window position with GetWindowRect.

    [DllImport("user32.dll")]  
    [return: MarshalAs(UnmanagedType.Bool)]  
    static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);  
    
    [StructLayout(LayoutKind.Sequential)]  
    public struct RECT  
    {
        public int Left;        // x position of upper-left corner  
        public int Top;         // y position of upper-left corner  
        public int Right;       // x position of lower-right corner  
        public int Bottom;      // y position of lower-right corner  
    }
    

提交回复
热议问题