private void ShellWinProc(Message msg) { if (msg.Msg == WM_SHELLHOOKMESSAGE) { try { var win = new ApplicationWindow(msg.LParam, this); lock (this._windowsLock) { switch (msg.WParam.ToInt32()) { case HSHELL_WINDOWCREATED: Trace.WriteLine("Created: " + msg.LParam.ToString()); addWindow(win); break; case HSHELL_WINDOWDESTROYED: Trace.WriteLine("Destroyed: " + msg.LParam.ToString()); removeWindow(win); break; case HSHELL_WINDOWREPLACING: Trace.WriteLine("Replacing: " + msg.LParam.ToString()); if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Inactive; win.OnPropertyChanged("ShowInTaskbar"); } else { win.State = ApplicationWindow.WindowState.Inactive; addWindow(win); } break; case HSHELL_WINDOWREPLACED: Trace.WriteLine("Replaced: " + msg.LParam.ToString()); removeWindow(win); break; case HSHELL_WINDOWACTIVATED: case HSHELL_RUDEAPPACTIVATED: Trace.WriteLine("Activated: " + msg.LParam.ToString()); foreach (var aWin in this.Windows.Where(w => w.State == ApplicationWindow.WindowState.Active)) { aWin.State = ApplicationWindow.WindowState.Inactive; } if (msg.LParam != IntPtr.Zero) { if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Active; win.OnPropertyChanged("ShowInTaskbar"); } else { win.State = ApplicationWindow.WindowState.Active; addWindow(win); } foreach (ApplicationWindow wind in this.Windows) { if (wind.WinFileName == win.WinFileName) { wind.OnPropertyChanged("ShowInTaskbar"); } } } break; case HSHELL_FLASH: Trace.WriteLine("Flashing window: " + msg.LParam.ToString()); if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Flashing; } else { win.State = ApplicationWindow.WindowState.Flashing; addWindow(win); } break; case HSHELL_ACTIVATESHELLWINDOW: Trace.WriteLine("Activate shell window called."); break; case HSHELL_ENDTASK: Trace.WriteLine("EndTask called: " + msg.LParam.ToString()); removeWindow(win); break; case HSHELL_GETMINRECT: Trace.WriteLine("GetMinRect called: " + msg.LParam.ToString()); SHELLHOOKINFO winHandle = (SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(SHELLHOOKINFO)); winHandle.rc = new RECT { bottom = 100, left = 0, right = 100, top = 0 }; Marshal.StructureToPtr(winHandle, msg.LParam, true); msg.Result = winHandle.hwnd; break; case HSHELL_REDRAW: Trace.WriteLine("Redraw called: " + msg.LParam.ToString()); if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.OnPropertyChanged("ShowInTaskbar"); win.OnPropertyChanged("Title"); win.SetIcon(); foreach (ApplicationWindow wind in this.Windows) { if (wind.WinFileName == win.WinFileName) { wind.OnPropertyChanged("ShowInTaskbar"); win.OnPropertyChanged("Title"); win.SetIcon(); } } } break; // TaskMan needs to return true if we provide our own task manager to prevent explorers. // case HSHELL_TASKMAN: // Trace.WriteLine("TaskMan Message received."); // break; default: Trace.WriteLine("Unknown called: " + msg.LParam.ToString() + " Message " + msg.Msg.ToString()); if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.OnPropertyChanged("ShowInTaskbar"); win.OnPropertyChanged("Title"); win.SetIcon(); } break; } } } catch (Exception ex) { Trace.WriteLine("Exception: " + ex.ToString()); Debugger.Break(); } } msg.Result = DefWindowProc(msg.HWnd, msg.Msg, msg.WParam, msg.LParam); }
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); }
private void ShellWinProc(System.Windows.Forms.Message msg) { if (msg.Msg == WM_SHELLHOOKMESSAGE) { try { var win = new ApplicationWindow(msg.LParam, this); lock (this._windowsLock) { switch (msg.WParam.ToInt32()) { case HSHELL_WINDOWCREATED: Trace.WriteLine("Created: " + msg.LParam.ToString()); Windows.Add(win); break; case HSHELL_WINDOWDESTROYED: Trace.WriteLine("Destroyed: " + msg.LParam.ToString()); if (this.Windows.Contains(win)) { this.Windows.Remove(win); } break; case HSHELL_WINDOWREPLACING: case HSHELL_WINDOWREPLACED: Trace.WriteLine("Replaced: " + msg.LParam.ToString()); if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Inactive; } else { win.State = ApplicationWindow.WindowState.Inactive; Windows.Add(win); } break; case HSHELL_WINDOWACTIVATED: case HSHELL_RUDEAPPACTIVATED: Trace.WriteLine("Activated: " + msg.LParam.ToString()); foreach (var aWin in this.Windows.Where(w => w.State == ApplicationWindow.WindowState.Active)) { aWin.State = ApplicationWindow.WindowState.Inactive; } if (msg.LParam == IntPtr.Zero) { break; } if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Active; } else { win.State = ApplicationWindow.WindowState.Active; Windows.Add(win); } break; case HSHELL_FLASH: Trace.WriteLine("Flashing window: " + msg.LParam.ToString()); if (this.Windows.Contains(win)) { win = this.Windows.First(wnd => wnd.Handle == msg.LParam); win.State = ApplicationWindow.WindowState.Flashing; } else { win.State = ApplicationWindow.WindowState.Flashing; Windows.Add(win); } break; case HSHELL_ACTIVATESHELLWINDOW: Trace.WriteLine("Activeate shell window called."); break; case HSHELL_ENDTASK: Trace.WriteLine("EndTask called."); break; case HSHELL_GETMINRECT: Trace.WriteLine("GetMinRect called."); SHELLHOOKINFO winHandle = (SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(SHELLHOOKINFO)); winHandle.rc.Top = 0; winHandle.rc.Left = 0; winHandle.rc.Bottom = 100; winHandle.rc.Right = 100; Marshal.StructureToPtr(winHandle, msg.LParam, true); msg.Result = winHandle.hwnd; break; case HSHELL_REDRAW: Trace.WriteLine("Redraw called."); this.OnRedraw(msg.LParam); break; // TaskMan needs to return true if we provide our own task manager to prevent explorers. // case HSHELL_TASKMAN: // Trace.WriteLine("TaskMan Message received."); // break; default: Trace.WriteLine("Uknown called. " + msg.Msg.ToString()); break; } } } catch (Exception ex) { Trace.WriteLine("Exception: " + ex.ToString()); Debugger.Break(); } } }