如何获得任何特定的工艺窗口大小?

时间:2016-05-27 00:09:56

标签: c# .net winforms

我在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

1 个答案:

答案 0 :(得分:1)

当窗口最小化时,窗口的位置为sort。因此,在您的示例中,{X=-32000,Y=-32000}的窗口最小化。

这种奇怪坐标背后的原因是因为与某些旧版Windows的向后兼容性。

  

Where did windows minimize to before the taskbar was invented?

     

Windows NT坚持-32000坐标并没有拿起   兼容性修复由于某种原因。我猜他们认为是的   时间Windows NT开始流行,所有那些破碎的程序都会有   已经修好了。

相关问题