예제 #1
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     SysTrayIcon.Dispose();
     SaveSettings();
     RunApplyTask = false;
     Externals.UnhookWinEvent(WindowStateHook);
 }
예제 #2
0
        public Taskbar(IntPtr hwnd)
        {
            HWND         = hwnd;
            Monitor      = Externals.MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
            AccentPolicy = new AccentPolicy();


            FindMaximizedWindowsHere();
        }
예제 #3
0
        public static void ApplyStyles(Taskbar taskbar)
        {
            int    sizeOfPolicy = Marshal.SizeOf(taskbar.AccentPolicy);
            IntPtr policyPtr    = Marshal.AllocHGlobal(sizeOfPolicy);

            Marshal.StructureToPtr(taskbar.AccentPolicy, policyPtr, false);

            WinCompatTrData data = new WinCompatTrData(WindowCompositionAttribute.WCA_ACCENT_POLICY, policyPtr, sizeOfPolicy);

            Externals.SetWindowCompositionAttribute(taskbar.HWND, ref data);

            Marshal.FreeHGlobal(policyPtr);
        }
예제 #4
0
        static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            //if ((idObject != 0 || idChild != 0) { return; }

            WindowPlacement placement = new WindowPlacement();

            placement.length = Marshal.SizeOf(placement);
            Externals.GetWindowPlacement(hwnd, ref placement);

            // Window is closing
            if (idObject == -2 && idChild == 5)
            {
                if (MaximizedWindows.Contains(hwnd))
                {
                    LastClosedWindow     = hwnd;
                    LastClosedWindowTime = DateTime.Now;
                    MaximizedWindows.Remove(hwnd);
                    Taskbars.MaximizedStateChanged = true;
                }
            }
            else if (placement.showCmd == WindowPlacementCommands.SW_MAXIMIZE || placement.showCmd == WindowPlacementCommands.SW_SHOWMAXIMIZED)
            {
                if (!MaximizedWindows.Contains(hwnd))
                {
                    if (LastClosedWindow == hwnd && ((TimeSpan)(DateTime.Now - LastClosedWindowTime)).TotalSeconds < 1)
                    {
                        return;
                    }

                    MaximizedWindows.Add(hwnd);
                    Taskbars.MaximizedStateChanged = true;
                }
            }
            else if (placement.showCmd == WindowPlacementCommands.SW_NORMAL)
            {
                if (MaximizedWindows.Contains(hwnd))
                {
                    MaximizedWindows.Remove(hwnd);
                    Taskbars.MaximizedStateChanged = true;
                }
            }
            else if (placement.showCmd == WindowPlacementCommands.SW_SHOWMINIMIZED || placement.showCmd == WindowPlacementCommands.SW_MINIMIZE)
            {
                if (MaximizedWindows.Contains(hwnd))
                {
                    MaximizedWindows.Remove(hwnd);
                    Taskbars.MaximizedStateChanged = true;
                }
            }
        }
예제 #5
0
        private void ApplyToAllTaskbars()
        {
            Taskbars.Bars = new List <Taskbar>();

            while (RunApplyTask)
            {
                if (FindTaskbarHandles)
                {
                    Taskbars.Bars.Add(new Taskbar(Externals.FindWindow("Shell_TrayWnd", null)));
                    //TaskbarList.Add(FindWindow(null, "Pins view"));
                    IntPtr otherBars = IntPtr.Zero;

                    //IntPtr cortana = FindWindowEx(hWndList[0], IntPtr.Zero, "TrayDummySearchControl", null);
                    //hWndList.Add(cortana);

                    while (true)
                    {
                        otherBars = Externals.FindWindowEx(IntPtr.Zero, otherBars, "Shell_SecondaryTrayWnd", "");
                        if (otherBars == IntPtr.Zero)
                        {
                            break;
                        }
                        else
                        {
                            Taskbars.Bars.Add(new Taskbar(otherBars));
                        }
                    }

                    FindTaskbarHandles = false;

                    App.Current.Dispatcher.Invoke(() => UpdateAllSettings());
                }

                if (Taskbars.MaximizedStateChanged)
                {
                    Taskbars.UpdateMaximizedState();
                    Taskbars.UpdateAllSettings();
                }

                foreach (Taskbar taskbar in Taskbars.Bars)
                {
                    Taskbars.ApplyStyles(taskbar);
                }

                Thread.Sleep(10);
            }
        }
예제 #6
0
        public void FindMaximizedWindowsHere()
        {
            bool   isInThisScreen = false;
            IntPtr thisAppMonitor;

            foreach (IntPtr hwnd in Globals.MaximizedWindows)
            {
                thisAppMonitor = Externals.MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
                if (Monitor == thisAppMonitor)
                {
                    isInThisScreen = true;
                }
            }

            HasMaximizedWindow = isInThisScreen;
            return;
        }
예제 #7
0
        private void Window_ContentRendered(object sender, EventArgs e)
        {
            PopulateComboBoxes();
            LoadSettings();
            WindowInitialized = true;

            if (TT.Options.Settings.StartMinimized)
            {
                this.WindowState = WindowState.Minimized;
            }
            if (TT.Options.Settings.StartWhenLaunched)
            {
                StartStopButton_Click(null, null);
            }

            // Listen for name change changes across all processes/threads on current desktop
            WindowStateHook = Externals.SetWinEventHook(EVENT_MIN, EVENT_MAX, IntPtr.Zero, procDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
        }