Csharp/C#教程:获取C#中的活动窗口坐标和高度宽度分享


获取C#中的活动窗口坐标和高度宽度

我只是在这里查看一些post,但没有一个对我有帮助。

我想要做的是运行Screen Capturing的后台进程。 现在我想要一段代码,它会给我X,Y或任何打开的Active / Current Window(Say Notepad)及其高度和宽度。

就是这样,没有别的。

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

然后使用GetWindowRect获取窗口位置。

上述就是C#学习教程:获取C#中的活动窗口坐标和高度宽度分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 [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 } 

  [DllImport("user32.dll")] private static extern bool SetProcessDPIAware(); [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect); static void Main() { SetProcessDPIAware(); Rectangle t2; GetWindowRect(GetForegroundWindow(),out t2); } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/988139.html

(0)
上一篇 2021年12月23日
下一篇 2021年12月23日

精彩推荐