我写了这段代码,但我无法隐藏和移动窗口。
如何在Process.Start()中隐藏窗口,然后将其移动并显示给用户?
[DllImport("USER32.dll")]
//[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("USER32.dll")]
private static extern bool UpdateWindow(IntPtr hWnd);
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Application.StartupPath + @"\award_star_gold_2.png";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = true;
Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
processTemp.Start();
processTemp.WaitForInputIdle();
IntPtr id = processTemp.MainWindowHandle;
Console.Write(id);
System.Threading.Thread.Sleep(1000);
MoveWindow(processTemp.MainWindowHandle, 10, 200, 200, 300, true);
UpdateWindow(processTemp.MainWindowHandle);
}