【发布时间】:2016-01-27 01:00:07
【问题描述】:
我正在尝试查找正在打开的新进程的窗口大小,但它的高度和宽度返回 0。这是我的代码:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
[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
}
static void Main(string[] args)
{
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files (x86)\FirstClass\fcc32.exe";
//C:\Program Files (x86)\FirstClass\fcc32.exe
process.Start();
Console.WriteLine(process.HandleCount);
IntPtr hWnd = process.MainWindowHandle;
RECT rect = new RECT();
process.WaitForInputIdle();
GetWindowRect(hWnd, ref rect);
int width = rect.Right - rect.Left;
int height = rect.Bottom - rect.Top;
Console.WriteLine("Height: " + height + ", Width: " + width);
Console.ReadLine();
}
【问题讨论】:
-
调用
GetWindowRect()的返回值是多少?是真是假? -
如果 process.MainWindowHandle 不为 NULL,那么我会在您的 fcc32 应用程序上使用 Spy++ 来查看该窗口的属性。可能是您的顶级窗口的大小为 0,0 ....并且充当创建的实际可见窗口的父级。也尝试调用“刷新”....stackoverflow.com/questions/16185217/…