Exemple #1
0
 public static void KillCurrent()
 {
     var    current  = LowLevel.GetForegroundWindow();
     UInt32 WM_CLOSE = 0x0010;
     IntPtr _zero    = IntPtr.Zero;
     IntPtr success  = LowLevel.SendMessage(current, WM_CLOSE, _zero, _zero);
 }
Exemple #2
0
        /// <summary>
        /// Force the foreground window to repaint
        /// </summary>
        public static void ForceRepaintForegroundWindow()
        {
            // get foreground process pointer
            IntPtr hWndForeground = LowLevel.GetForegroundWindow();

            // force the repaint
            LowLevel.SendMessage(hWndForeground, LowLevel.WmPaint, 0, 0);
        }
Exemple #3
0
        /// <summary>
        /// get the process that is the current foreground window
        /// </summary>
        /// <returns>the process of the foreground window</returns>
        public static Process GetForegroundProcess()
        {
            // get foreground process pointer
            IntPtr hWndForeground = LowLevel.GetForegroundWindow();

            // get PID for that pointer
            LowLevel.GetWindowThreadProcessId(hWndForeground, out uint fgPid);

            // get process by pid
            return(Process.GetProcessById((int)fgPid));
        }
Exemple #4
0
 public static Process GetCurrentWorkingProcess()
 {
     try
     {
         return(Process.GetProcesses().FirstOrDefault(p => p.MainWindowHandle == LowLevel.GetForegroundWindow()));
     }
     catch (System.ComponentModel.Win32Exception e) { RunningWindow.Log(e.Message + " " + e.NativeErrorCode + " " + e.Source + " " + e.StackTrace); }
     return(null);
 }