我想使用MoveWindow API调整外部应用程序的大小
但每一次,我都会收到此错误:Form already displayed; can't show modally (Error 400)。
显然,我不关心窗口的模态和/或非模态模式,我只想调整它的大小。
MoveWindow()
函数始终返回true
,但错误来自目标应用程序
我使用的是Windows 7 Home Edition
和.Net 4.0
谁能引导我走向正确的方向?还是给我一个线索?
这是我的代码:
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("kernel32.dll")]
static extern uint GetLastError();
static void Main(string[] args)
{
var hWnd = FindWindow(null, "foodsoft_aminpardazco_1388");
if (hWnd != null)
{
bool result = MoveWindow(hWnd, 0, 0, 100, 100, false);
Console.WriteLine(result?"hooraaa!":"error:"+GetLastError());
}
else
Console.WriteLine("eeeee");
Console.ReadKey();
}
该消息告诉我,你无法在模态模式下显示已经显示的形式,所以我想在非模态模式下调整此窗口的大小。你有什么想法吗?