Prozess im Windows auswählen und Fenster aktivieren/maximieren
-
Grüßt Euch,
ich suche eine Möglichkeit wie ich eine Anwendung im Windows auswählen kann, und diese dann in den Vordergrund hebe. Schließen konnte ich die Anwendung mit System.Diagnostics.Process schon.
Gruß
Markus Seidl
-
So ich habs mir jetzt mit der WinAPI selbst zusammen gepfrimelt. Ich setz die Lösung jetzt einfach mal hier rein, für alle die es in Zukunft vielleicht interessiert.
namespace CustomViewChanger { class MainClass { public static void Main(string[] args) { Process[] myCustomViews = Process.GetProcessesByName("Notepad"); Win32.SetForegroundWindow(myCustomViews[0].MainWindowHandle); System.Threading.Thread.Sleep(1000); Win32.SetForegroundWindow(myCustomViews[1].MainWindowHandle); System.Threading.Thread.Sleep(1000); } } public class Win32 { public const int WM_SYSCOMMAND = 0x0112; public const int SC_SIZE = 0xF000; public const int SC_MOVE = 0xF010; public const int SC_MINIMIZE = 0xF020; public const int SC_MAXIMIZE = 0xF030; public const int SC_NEXTWINDOW = 0xF040; public const int SC_PREVWINDOW = 0xF050; public const int SC_CLOSE = 0xF060; public const int SC_VSCROLL = 0xF070; public const int SC_HSCROLL = 0xF080; public const int SC_MOUSEMENU = 0xF090; public const int SC_KEYMENU = 0xF100; public const int SC_ARRANGE = 0xF110; public const int SC_RESTORE = 0xF120; public const int SC_TASKLIST = 0xF130; public const int SC_SCREENSAVE = 0xF140; public const int SC_HOTKEY = 0xF150; public const int SC_DEFAULT = 0xF160; public const int SC_MONITORPOWER= 0xF170; public const int SC_CONTEXTHELP = 0xF180; public const int SC_SEPARATOR = 0xF00F; [DllImport("user32.dll")] public static extern int SendMessage( int hWnd, uint Msg, int wParam, int lParam ); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); } }
Mit dem Code sind auch noch gleich einige Konstanten dabei, um mit dem Fenster ein paar Dinge anstellen zu können.
Gruß
Markus Seidl