无法最大化外部进程的窗口
本文关键字:窗口 进程 外部 最大化 | 更新日期: 2023-09-27 18:07:51
到目前为止,我还没有成功地最大化外部窗口。我可以把手柄放到前台。但它不会最大化。
Process[] processlist = Process.GetProcesses();
IntPtr handle;
foreach (Process process in processlist)
{
if (process.ProcessName == "wfica32")
{
handle = process.MainWindowHandle;
SetForegroundWindow(handle);
ShowWindowAsync(handle, 3); // or SW_SHOWMAXIMIZED// = 3;
}
}
您需要使用'ProcessID'而不是process。
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SwShowmaximized = 3;
private void Run()
{
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist.Where(process => process.ProcessName == "wfica32"))
{
ShowWindow(Process.GetProcessById(process.Id).MainWindowHandle, SwShowmaximized);
}
}
您可以尝试不安全的方法。
// Pinvoke declaration for ShowWindow
private const int SW_SHOWMAXIMIZED = 3;
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
// Sample usage
ShowWindow(proc.MainWindowHandle, SW_SHOWMAXIMIZED);