简体   繁体   English

如何获得任何特定的进程窗口大小?

[英]How can I get any specific process window size?

I tried this in top of form1我在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; }
}

Then in constructor然后在构造函数中

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

But the result is strange I think.但我认为结果很奇怪。 In mspainRect using a break point I see在使用断点的mspainRect我看到

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

When a window is minimized the location of windows is {X=-32000,Y=-32000} .当窗口最小化时,窗口的位置是{X=-32000,Y=-32000} So it seems in your example case, window of mspaint is minimized.因此,在您的示例中, mspaint窗口似乎已最小化。

The reason behind this strange coordinates is because of backward compatibility with some old versions of Windows.这个奇怪坐标背后的原因是因为与一些旧版本的 Windows 向后兼容。

Where did windows minimize to before the taskbar was invented? 在任务栏发明之前,窗口最小化到哪里?

Windows NT stuck with the -32000 coordinates and didn't pick up the compatibility fixes for some reason. Windows NT 坚持使用 -32000 坐标并且由于某种原因没有选择兼容性修复程序。 I guess they figured that by the time Windows NT became popular, all those broken programs would have been fixed.我猜他们认为当 Windows NT 流行时,所有那些损坏的程序都会得到修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM