gpt4 book ai didi

c# - 我怎样才能得到任何特定的过程窗口大小?

转载 作者:太空宇宙 更新时间:2023-11-03 12:45:29 26 4
gpt4 key购买 nike

我在 form1 的顶部试过这个

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect1 rectangle);

public struct Rect1
{
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
}

然后在构造函数中

Process[] processes1 = Process.GetProcessesByName("mspaint");
Process lol = processes1[0];
IntPtr ptr = lol.MainWindowHandle;
Rect1 mspaintRect = new Rect1();
GetWindowRect(ptr, ref mspaintRect);

但我认为结果很奇怪。在 mspainRect 中使用我看到的断点

Bottom = -31972
Left = -32000
Right = -31840
Top = -32000

最佳答案

当窗口最小化时,窗口的位置是{X=-32000,Y=-32000}。因此,在您的示例中,mspaint 的窗口似乎已最小化。

这个奇怪坐标背后的原因是因为向后兼容一些旧版本的 Windows。

Where did windows minimize to before the taskbar was invented?

Windows NT stuck with the -32000 coordinates and didn’t pick up thecompatibility fixes for some reason. I guess they figured that by thetime Windows NT became popular, all those broken programs would havebeen fixed.

关于c# - 我怎样才能得到任何特定的过程窗口大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37472906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com