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