Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DllImport("user32.dll")]
- internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll")]
- internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); //ShowWindow needs an IntPtr
- private static void FocusProcess()
- {
- IntPtr hWnd; //change this to IntPtr
- Process[] processRunning = Process.GetProcesses();
- foreach (Process pr in processRunning)
- {
- if (pr.ProcessName == "notepad")
- {
- hWnd = pr.MainWindowHandle; //use it as IntPtr not int
- ShowWindow(hWnd, 3);
- SetForegroundWindow(hWnd); //set to topmost
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement