本文介绍了在 C# 中获取活动窗口坐标和高度宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我只是查看了这里的一些帖子,但没有一个对我有帮助.
I just check in some of the posts here, but none were helpful to me.
我想做的是运行屏幕捕获的后台进程.现在我想要一段代码,它可以为我提供 X、Y 或任何打开的活动/当前窗口(比如记事本)及其高度和宽度.
The thing I am trying to do is to run a background process of Screen Capturing. Now I want a piece of code that would give me the X, Y or any Active/Current Window opened (Say Notepad) and its Height and Width.
仅此而已.
推荐答案
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
private IntPtr GetActiveWindow()
{
IntPtr handle = IntPtr.Zero;
return GetForegroundWindow();
}
然后使用 GetWindowRect 获取窗口位置.
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
}
这篇关于在 C# 中获取活动窗口坐标和高度宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论