private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { SysTrayIcon.Dispose(); SaveSettings(); RunApplyTask = false; Externals.UnhookWinEvent(WindowStateHook); }
public Taskbar(IntPtr hwnd) { HWND = hwnd; Monitor = Externals.MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); AccentPolicy = new AccentPolicy(); FindMaximizedWindowsHere(); }
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); }
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; } } }
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); } }
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; }
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); }