在process.start()中隐藏窗口并移动此窗口

时间:2015-10-18 14:34:00

标签: c#-4.0

我写了这段代码,但我无法隐藏和移动窗口。

如何在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);
}

0 个答案:

没有答案