Advertisement
Guest User

Untitled

a guest
Aug 12th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1.     [DllImport("user32.dll")]
  2.     internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);
  3.  
  4.     [DllImport("user32.dll")]
  5.     internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); //ShowWindow needs an IntPtr
  6.  
  7.     private static void FocusProcess()
  8.     {
  9.         IntPtr hWnd; //change this to IntPtr
  10.         Process[] processRunning = Process.GetProcesses();
  11.         foreach (Process pr in processRunning)
  12.         {
  13.             if (pr.ProcessName == "notepad")
  14.             {
  15.                 hWnd = pr.MainWindowHandle; //use it as IntPtr not int
  16.                 ShowWindow(hWnd, 3);
  17.                 SetForegroundWindow(hWnd); //set to topmost
  18.             }
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement