Wie kann ich einen Prozess in C # ein- oder ausblenden?
Ich versuche, einen externen Prozess in einer Visual C # 2010 - Windows Forms-Anwendung zu starten. Ziel ist es, den Vorgang als verstecktes Fenster zu starten und das Fenster zu einem späteren Zeitpunkt wieder einzublenden.
Ich habe meinen Fortschritt aktualisiert:
<code>//Initialization [DllImport("user32.dll")] private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow); [DllImport("user32.dll")] private static extern bool EnableWindow(IntPtr hwnd, bool enable); [DllImport("user32.dll")] private static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw); SW_SHOW = 5; </code>
Folgendes wurde in meine Hauptfunktion gestellt:
<code>ProcessStartInfo info = new ProcessStartInfo("process.exe"); info.WindowStyle = ProcessWindowStyle.Hidden; Process p = Process.Start(info); p.WaitForInputIdle(); IntPtr HWND = p.MainWindowHandle; System.Threading.Thread.Sleep(1000); ShowWindow(HWND, SW_SHOW); EnableWindow(HWND, true); MoveWindow(HWND, 0, 0, 640, 480, true); </code>
Da das Fenster jedoch als "versteckt" gestartet wurde,p.MainWindowHandle = 0
. Ich kann das Fenster nicht erfolgreich anzeigen. Ich habe es auch versuchtHWND = p.Handle
ohne erfolg.
Gibt es eine Möglichkeit, meinem Fenster ein neues Handle zu geben? Dies könnte möglicherweise mein Problem beheben.
Verweise: