Example #1
0
 internal bool IsMatch(IntPtr hWnd, string cName, string dName, string pName, NativeMethods.WS style, NativeMethods.WS_EX exStyle)
 {
     return(className.IsMatch(cName) && displayName.IsMatch(dName) && processName.IsMatch(pName) &&
            (style & styleContains) == styleContains && (style & styleNotContains) == 0 &&
            (exStyle & exStyleContains) == exStyleContains && (exStyle & exStyleNotContains) == 0 &&
            customMatchingFunction(hWnd));
 }
Example #2
0
        internal Window(IntPtr hWnd, string className, string displayName, string processName, int workspacesCount, bool is64BitProcess,
            NativeMethods.WS originalStyle, NativeMethods.WS_EX originalExStyle, ProgramRule.Rule rule, ProgramRule programRule, IntPtr menu)
            : base(hWnd)
        {
            IsFloating = rule.isFloating;
            Titlebar = rule.titlebar;
            InAltTabAndTaskbar = rule.inAltTabAndTaskbar;
            WindowBorders = rule.windowBorders;
            this.WorkspacesCount = workspacesCount;
            this.DisplayName = displayName;
            this.className = className;
            this.processName = processName;
            this.is64BitProcess = is64BitProcess;
            redrawOnShow = rule.redrawOnShow;
            ShowMenu = programRule.showMenu;
            updateIcon = programRule.updateIcon;
            onHiddenWindowShownAction = programRule.onHiddenWindowShownAction;
            this.menu = menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = rule.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle = originalStyle;
            this.originalExStyle = originalExStyle;

            windowPlacement = NativeMethods.WINDOWPLACEMENT.Default;
            SavePosition();
            originalWindowPlacement = windowPlacement;

            this.customOwnedWindowMatchingFunction = programRule.customOwnedWindowMatchingFunction;

            this.ownedWindows = new LinkedList<IntPtr>();
            this.ownedWindows.AddFirst(hWnd);
        }
Example #3
0
        internal Window(Window window)
            : base(window)
        {
            this.IsFloating = window.IsFloating;
            this.Titlebar = window.Titlebar;
            this.InAltTabAndTaskbar = window.InAltTabAndTaskbar;
            this.WindowBorders = window.WindowBorders;
            this.WorkspacesCount = window.WorkspacesCount;
            this.DisplayName = window.DisplayName;
            className = window.className;
            processName = window.processName;
            is64BitProcess = window.is64BitProcess;
            redrawOnShow = window.redrawOnShow;
            ShowMenu = window.ShowMenu;
            updateIcon = window.updateIcon;
            onHiddenWindowShownAction = window.onHiddenWindowShownAction;
            menu = window.menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle = window.originalStyle;
            this.originalExStyle = window.originalExStyle;

            windowPlacement = window.windowPlacement;
            originalWindowPlacement = window.originalWindowPlacement;

            this.customOwnedWindowMatchingFunction = window.customOwnedWindowMatchingFunction;
            ownedWindows = window.ownedWindows;
        }
Example #4
0
        internal Window(Window window) : base(window)
        {
            this.IsFloating         = window.IsFloating;
            this.Titlebar           = window.Titlebar;
            this.InAltTabAndTaskbar = window.InAltTabAndTaskbar;
            this.WindowBorders      = window.WindowBorders;
            this.WorkspacesCount    = window.WorkspacesCount;
            this.DisplayName        = window.DisplayName;
            className                 = window.className;
            processName               = window.processName;
            is64BitProcess            = window.is64BitProcess;
            redrawOnShow              = window.redrawOnShow;
            ShowMenu                  = window.ShowMenu;
            updateIcon                = window.updateIcon;
            onHiddenWindowShownAction = window.onHiddenWindowShownAction;
            menu = window.menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle   = window.originalStyle;
            this.originalExStyle = window.originalExStyle;

            windowPlacement         = window.windowPlacement;
            originalWindowPlacement = window.originalWindowPlacement;

            this.customOwnedWindowMatchingFunction = window.customOwnedWindowMatchingFunction;
            ownedWindows = window.ownedWindows;
        }
Example #5
0
        internal Window(IntPtr hWnd, string className, string displayName, string processName, int workspacesCount, bool is64BitProcess,
                        NativeMethods.WS originalStyle, NativeMethods.WS_EX originalExStyle, ProgramRule.Rule rule, ProgramRule programRule, IntPtr menu) :
            base(hWnd)
        {
            IsFloating                = rule.isFloating;
            Titlebar                  = rule.titlebar;
            InAltTabAndTaskbar        = rule.inAltTabAndTaskbar;
            WindowBorders             = rule.windowBorders;
            this.WorkspacesCount      = workspacesCount;
            this.DisplayName          = displayName;
            this.className            = className;
            this.processName          = processName;
            this.is64BitProcess       = is64BitProcess;
            redrawOnShow              = rule.redrawOnShow;
            ShowMenu                  = programRule.showMenu;
            updateIcon                = programRule.updateIcon;
            onHiddenWindowShownAction = programRule.onHiddenWindowShownAction;
            this.menu                 = menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = rule.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle   = originalStyle;
            this.originalExStyle = originalExStyle;

            windowPlacement = NativeMethods.WINDOWPLACEMENT.Default;
            SavePosition();
            originalWindowPlacement = windowPlacement;

            this.customOwnedWindowMatchingFunction = programRule.customOwnedWindowMatchingFunction;

            this.ownedWindows = new LinkedList <IntPtr>();
            this.ownedWindows.AddFirst(hWnd);
        }
Example #6
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            IntPtr handle = new WindowInteropHelper(this).Handle;

            NativeMethods.WS wsEx = UnsafeNativeMethods.GetWindowLong(handle, NativeMethods.GWL.EXSTYLE);

            UnsafeNativeMethods.SetWindowLong(handle, NativeMethods.GWL.EXSTYLE, wsEx | NativeMethods.WS.EX_TRANSPARENT);
        }
Example #7
0
        public ProgramRule(string className = ".*", string displayName = ".*", string processName = ".*",
                           NativeMethods.WS styleContains                = (NativeMethods.WS) 0, NativeMethods.WS styleNotContains = (NativeMethods.WS) 0,
                           NativeMethods.WS_EX exStyleContains           = (NativeMethods.WS_EX) 0, NativeMethods.WS_EX exStyleNotContains = (NativeMethods.WS_EX) 0,
                           CustomMatchingFunction customMatchingFunction = null, CustomMatchingFunction customOwnedWindowMatchingFunction  = null,

                           bool isManaged = true, int tryAgainAfter = -1, int windowCreatedDelay = -1, bool redrawDesktopOnWindowCreated = false,
                           bool showMenu  = true, bool updateIcon   = false,
                           OnWindowCreatedOrShownAction onWindowCreatedAction     = OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace,
                           OnWindowCreatedOrShownAction onHiddenWindowShownAction = OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace,
                           OnWindowCreatedOnWorkspaceAction onWindowCreatedOnCurrentWorkspaceAction  = OnWindowCreatedOnWorkspaceAction.MoveToTop,
                           OnWindowCreatedOnWorkspaceAction onWindowCreatedOnInactiveWorkspaceAction = OnWindowCreatedOnWorkspaceAction.MoveToTop,
                           int showOnWorkspacesCount = 0, IEnumerable <Rule> rules = null)
        {
            this.className                         = new Regex(className, RegexOptions.Compiled);
            this.displayName                       = new Regex(displayName, RegexOptions.Compiled);
            this.processName                       = new Regex(processName, RegexOptions.Compiled);
            this.styleContains                     = styleContains;
            this.styleNotContains                  = styleNotContains;
            this.exStyleContains                   = exStyleContains;
            this.exStyleNotContains                = exStyleNotContains;
            this.customMatchingFunction            = customMatchingFunction ?? Utilities.IsAltTabWindow;
            this.customOwnedWindowMatchingFunction = customOwnedWindowMatchingFunction ?? DefaultOwnedWindowMatchingFunction;

            this.isManaged = isManaged;
            if (isManaged)
            {
                this.tryAgainAfter                = tryAgainAfter;
                this.windowCreatedDelay           = windowCreatedDelay;
                this.redrawDesktopOnWindowCreated = redrawDesktopOnWindowCreated;
                this.showMenu                  = showMenu;
                this.updateIcon                = updateIcon;
                this.onWindowCreatedAction     = onWindowCreatedAction;
                this.onHiddenWindowShownAction = onHiddenWindowShownAction;
                this.onWindowCreatedOnCurrentWorkspaceAction  = onWindowCreatedOnCurrentWorkspaceAction;
                this.onWindowCreatedOnInactiveWorkspaceAction = onWindowCreatedOnInactiveWorkspaceAction;

                if (showOnWorkspacesCount > 0)
                {
                    if (rules == null)
                    {
                        rules = new Rule[] { };
                    }

                    // This is slow (n ^ 2), but it doesn't matter in this case
                    this.rules = rules.Concat(
                        Enumerable.Range(1, showOnWorkspacesCount).Where(i => rules.All(r => r.workspace != i)).Select(i => new Rule(i))).
                                 ToArray();
                }
                else
                {
                    this.rules = rules == null ? new[] { new Rule() } : rules.ToArray();
                }
            }
        }
Example #8
0
        /// <summary>
        ///  This method is used to toggle style flags from an hwnd.
        /// </summary>
        /// <param name="hwnd">The hwnd on which styles are being chaned</param>
        /// <param name="removeStyle">Style Flags to remove</param>
        /// <param name="addStyle">Style Flags to add</param>
        /// <returns>Boolean True is there was some change.  False if no flags were added or removed.</returns>
        internal static bool ModifyHwndStyle(IntPtr hwnd, NativeMethods.WS removeStyle, NativeMethods.WS addStyle)
        {
            var curWindowStyle = (NativeMethods.WS)NativeMethods.GetWindowLongPtr(hwnd, NativeMethods.GWL.STYLE).ToInt32();
            var newStyle       = (curWindowStyle & ~removeStyle) | addStyle;

            if (curWindowStyle == newStyle)
            {
                return(false);
            }

            NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GWL.STYLE, new IntPtr((int)newStyle));
            return(true);
        }
Example #9
0
        public ProgramRule(string className = ".*", string displayName = ".*", string processName = ".*",
            NativeMethods.WS styleContains = (NativeMethods.WS) 0, NativeMethods.WS styleNotContains = (NativeMethods.WS) 0,
            NativeMethods.WS_EX exStyleContains = (NativeMethods.WS_EX) 0, NativeMethods.WS_EX exStyleNotContains = (NativeMethods.WS_EX) 0,
            CustomMatchingFunction customMatchingFunction = null, CustomMatchingFunction customOwnedWindowMatchingFunction = null,
            
            bool isManaged = true, int tryAgainAfter = -1, int windowCreatedDelay = -1, bool redrawDesktopOnWindowCreated = false,
            bool showMenu = true, bool updateIcon = false,
            OnWindowCreatedOrShownAction onWindowCreatedAction = OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace,
            OnWindowCreatedOrShownAction onHiddenWindowShownAction = OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace,
            OnWindowCreatedOnWorkspaceAction onWindowCreatedOnCurrentWorkspaceAction = OnWindowCreatedOnWorkspaceAction.MoveToTop,
            OnWindowCreatedOnWorkspaceAction onWindowCreatedOnInactiveWorkspaceAction = OnWindowCreatedOnWorkspaceAction.MoveToTop,
            int showOnWorkspacesCount = 0, IEnumerable<Rule> rules = null)
        {
            this.className = new Regex(className, RegexOptions.Compiled);
            this.displayName = new Regex(displayName, RegexOptions.Compiled);
            this.processName = new Regex(processName, RegexOptions.Compiled);
            this.styleContains = styleContains;
            this.styleNotContains = styleNotContains;
            this.exStyleContains = exStyleContains;
            this.exStyleNotContains = exStyleNotContains;
            this.customMatchingFunction = customMatchingFunction ?? Utilities.IsAltTabWindow;
            this.customOwnedWindowMatchingFunction = customOwnedWindowMatchingFunction ?? DefaultOwnedWindowMatchingFunction;

            this.isManaged = isManaged;
            if (isManaged)
            {
                this.tryAgainAfter = tryAgainAfter;
                this.windowCreatedDelay = windowCreatedDelay;
                this.redrawDesktopOnWindowCreated = redrawDesktopOnWindowCreated;
                this.showMenu = showMenu;
                this.updateIcon = updateIcon;
                this.onWindowCreatedAction = onWindowCreatedAction;
                this.onHiddenWindowShownAction = onHiddenWindowShownAction;
                this.onWindowCreatedOnCurrentWorkspaceAction = onWindowCreatedOnCurrentWorkspaceAction;
                this.onWindowCreatedOnInactiveWorkspaceAction = onWindowCreatedOnInactiveWorkspaceAction;

                if (showOnWorkspacesCount > 0)
                {
                    if (rules == null)
                    {
                        rules = new Rule[] { };
                    }

                    // This is slow (n ^ 2), but it doesn't matter in this case
                    this.rules = rules.Concat(
                        Enumerable.Range(1, showOnWorkspacesCount).Where(i => rules.All(r => r.workspace != i)).Select(i => new Rule(i))).
                        ToArray();
                }
                else
                {
                    this.rules = rules == null ? new[] { new Rule() } : rules.ToArray();
                }
            }
        }
Example #10
0
 private void OnProgramRuleMatched(ProgramRule programRule, IntPtr hWnd, string className, string displayName, string processName, NativeMethods.WS style, NativeMethods.WS_EX exStyle)
 {
     if (programRule != null)
     {
         writer.WriteLine("MATCHED - class '{0}'; caption '{1}'; processName '{2}';",
                          className, displayName, processName);
         writer.WriteLine("\tAGAINST RULE WITH class '{0}'; caption '{1}'; process name '{2}';",
                          programRule.className, programRule.displayName, programRule.processName);
         writer.WriteLine("\tstyle contains: '{0}'; style not contains '{1}'; ex style contains '{2}'; ex style not contains '{3}'; is managed '{4}'",
                          programRule.styleContains, programRule.styleNotContains, programRule.exStyleContains, programRule.exStyleNotContains, programRule.isManaged);
     }
     else
     {
         writer.WriteLine("COULD NOT MATCH - class '{0}'; caption '{1}'; processName '{2}' AGAINST ANY RULE",
                          className, displayName, processName);
     }
 }
Example #11
0
 public static extern int SetWindowLong(IntPtr hWnd, NativeMethods.GWL nIndex, NativeMethods.WS dwNewLong);