private void getInitialWindows() { EnumWindows((hwnd, lParam) => { ApplicationWindow win = new ApplicationWindow(hwnd); // set window category if provided by shell win.Category = TaskCategoryProvider?.GetCategory(win); if (win.CanAddToTaskbar && win.ShowInTaskbar && !Windows.Contains(win)) { Windows.Add(win); } return(true); }, 0); IntPtr hWndForeground = GetForegroundWindow(); if (Windows.Any(i => i.Handle == hWndForeground && i.ShowInTaskbar)) { ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWndForeground); win.State = ApplicationWindow.WindowState.Active; win.SetShowInTaskbar(); } }
private void ShellWinProc(Message msg) { if (msg.Msg == WM_SHELLHOOKMESSAGE) { try { lock (_windowsLock) { switch ((HSHELL)msg.WParam.ToInt32()) { case HSHELL.WINDOWCREATED: CairoLogger.Instance.Debug("Created: " + msg.LParam.ToString()); if (!Windows.Any(i => i.Handle == msg.LParam)) { addWindow(msg.LParam); } else { ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam); win.UpdateProperties(); } break; case HSHELL.WINDOWDESTROYED: CairoLogger.Instance.Debug("Destroyed: " + msg.LParam.ToString()); removeWindow(msg.LParam); break; case HSHELL.WINDOWREPLACING: CairoLogger.Instance.Debug("Replacing: " + msg.LParam.ToString()); if (Windows.Any(i => i.Handle == msg.LParam)) { ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Inactive; win.SetShowInTaskbar(); } else { addWindow(msg.LParam); } break; case HSHELL.WINDOWREPLACED: CairoLogger.Instance.Debug("Replaced: " + msg.LParam.ToString()); removeWindow(msg.LParam); break; case HSHELL.WINDOWACTIVATED: case HSHELL.RUDEAPPACTIVATED: CairoLogger.Instance.Debug("Activated: " + msg.LParam.ToString()); foreach (var aWin in Windows.Where(w => w.State == ApplicationWindow.WindowState.Active)) { aWin.State = ApplicationWindow.WindowState.Inactive; } if (msg.LParam != IntPtr.Zero) { ApplicationWindow win = null; if (Windows.Any(i => i.Handle == msg.LParam)) { win = Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Active; win.SetShowInTaskbar(); } else { win = addWindow(msg.LParam, ApplicationWindow.WindowState.Active); } if (win != null) { foreach (ApplicationWindow wind in Windows) { if (wind.WinFileName == win.WinFileName) { wind.SetShowInTaskbar(); } } } } break; case HSHELL.FLASH: CairoLogger.Instance.Debug("Flashing window: " + msg.LParam.ToString()); if (Windows.Any(i => i.Handle == msg.LParam)) { ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Flashing; } else { addWindow(msg.LParam, ApplicationWindow.WindowState.Flashing, true); } break; case HSHELL.ACTIVATESHELLWINDOW: CairoLogger.Instance.Debug("Activate shell window called."); break; case HSHELL.ENDTASK: CairoLogger.Instance.Debug("EndTask called: " + msg.LParam.ToString()); removeWindow(msg.LParam); break; case HSHELL.GETMINRECT: CairoLogger.Instance.Debug("GetMinRect called: " + msg.LParam.ToString()); SHELLHOOKINFO winHandle = (SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(SHELLHOOKINFO)); winHandle.rc = new Interop.NativeMethods.Rect { Bottom = 100, Left = 0, Right = 100, Top = 0 }; Marshal.StructureToPtr(winHandle, msg.LParam, true); msg.Result = winHandle.hwnd; return; // return here so the result isnt reset to DefWindowProc case HSHELL.REDRAW: CairoLogger.Instance.Debug("Redraw called: " + msg.LParam.ToString()); if (Windows.Any(i => i.Handle == msg.LParam)) { ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam); win.UpdateProperties(); foreach (ApplicationWindow wind in Windows) { if (wind.WinFileName == win.WinFileName) { wind.UpdateProperties(); } } } else { addWindow(msg.LParam, ApplicationWindow.WindowState.Inactive, true); } break; // TaskMan needs to return true if we provide our own task manager to prevent explorers. // case HSHELL.TASKMAN: // SingletonLogger.Instance.Info("TaskMan Message received."); // break; default: break; } } } catch (Exception ex) { CairoLogger.Instance.Error("Error in ShellWinProc. ", ex); Debugger.Break(); } } else if (msg.Msg == WM_TASKBARCREATEDMESSAGE) { CairoLogger.Instance.Debug("TaskbarCreated received, setting ITaskbarList window"); setTaskbarListHwnd(); } else { // Handle ITaskbarList functions, most not implemented yet ApplicationWindow win = null; switch (msg.Msg) { case (int)WM.USER + 50: // ActivateTab // Also sends WM_SHELLHOOK message CairoLogger.Instance.Debug("ITaskbarList: ActivateTab HWND:" + msg.LParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 60: // MarkFullscreenWindow CairoLogger.Instance.Debug("ITaskbarList: MarkFullscreenWindow HWND:" + msg.LParam + " Entering? " + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 64: // SetProgressValue CairoLogger.Instance.Debug("ITaskbarList: SetProgressValue HWND:" + msg.WParam + " Progress: " + msg.LParam); win = new ApplicationWindow(msg.WParam, this); if (Windows.Contains(win)) { win = Windows.First(wnd => wnd.Handle == msg.WParam); win.ProgressValue = (int)msg.LParam; } msg.Result = IntPtr.Zero; return; case (int)WM.USER + 65: // SetProgressState CairoLogger.Instance.Debug("ITaskbarList: SetProgressState HWND:" + msg.WParam + " Flags: " + msg.LParam); win = new ApplicationWindow(msg.WParam, this); if (Windows.Contains(win)) { win = Windows.First(wnd => wnd.Handle == msg.WParam); win.ProgressState = (TBPFLAG)msg.LParam; } msg.Result = IntPtr.Zero; return; case (int)WM.USER + 67: // RegisterTab CairoLogger.Instance.Debug("ITaskbarList: RegisterTab MDI HWND:" + msg.LParam + " Tab HWND: " + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 68: // UnregisterTab CairoLogger.Instance.Debug("ITaskbarList: UnregisterTab Tab HWND: " + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 71: // SetTabOrder CairoLogger.Instance.Debug("ITaskbarList: SetTabOrder HWND:" + msg.WParam + " Before HWND: " + msg.LParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 72: // SetTabActive CairoLogger.Instance.Debug("ITaskbarList: SetTabActive HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 75: // Unknown CairoLogger.Instance.Debug("ITaskbarList: Unknown HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 76: // ThumbBarAddButtons CairoLogger.Instance.Debug("ITaskbarList: ThumbBarAddButtons HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 77: // ThumbBarUpdateButtons CairoLogger.Instance.Debug("ITaskbarList: ThumbBarUpdateButtons HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 78: // ThumbBarSetImageList CairoLogger.Instance.Debug("ITaskbarList: ThumbBarSetImageList HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 79: // SetOverlayIcon - Icon CairoLogger.Instance.Debug("ITaskbarList: SetOverlayIcon - Icon HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 80: // SetThumbnailTooltip CairoLogger.Instance.Debug("ITaskbarList: SetThumbnailTooltip HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 81: // SetThumbnailClip CairoLogger.Instance.Debug("ITaskbarList: SetThumbnailClip HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 85: // SetOverlayIcon - Description CairoLogger.Instance.Debug("ITaskbarList: SetOverlayIcon - Description HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; case (int)WM.USER + 87: // SetTabProperties CairoLogger.Instance.Debug("ITaskbarList: SetTabProperties HWND:" + msg.WParam); msg.Result = IntPtr.Zero; return; } } msg.Result = DefWindowProc(msg.HWnd, msg.Msg, msg.WParam, msg.LParam); }