private bool IsSupportShellEvents(User32.ShellEvents shellEvents) { return(shellEvents != User32.ShellEvents.HSHELL_WINDOWACTIVATED && shellEvents != User32.ShellEvents.HSHELL_WINDOWDESTROYED && shellEvents != User32.ShellEvents.HSHELL_WINDOWCREATED && shellEvents != User32.ShellEvents.HSHELL_RUDEAPPACTIVATED); }
private void OnShellWndProc(IntPtr hWnd, User32.ShellEvents shellEvents) { if (IsSupportShellEvents(shellEvents)) { return; } int pId = User32.GetWindowThreadProcessId(hWnd); if (shellEvents == User32.ShellEvents.HSHELL_RUDEAPPACTIVATED) { if (_foregroundProcess?.Id == pId) { SetActionType(_foregroundProcess, _foregroundHandle, ActionType.Blur); _foregroundProcess = null; _foregroundHandle = IntPtr.Zero; } } if (pId <= 0) { return; } if (User32.GetAncestor(hWnd, User32.GetAncestorFlags.GetRootOwner) != hWnd || !User32.IsWindowEnabled(hWnd)) { return; } if (shellEvents == User32.ShellEvents.HSHELL_WINDOWDESTROYED) { if (!User32.IsWindow(hWnd)) { return; } } else { if (!User32.IsWindowVisible(hWnd) || !User32.IsWindow(hWnd)) { return; } } var proessInfo = new ProcessInfo(pId); if (!File.Exists(proessInfo.FileName)) { return; } SetActionType(proessInfo, hWnd, ShellEventToActionType(shellEvents)); }
private ActionType ShellEventToActionType(User32.ShellEvents events) => events switch {