Esempio n. 1
0
        public static void ShellWinProc(System.Windows.Forms.Message msg)
        {
            try
            {
                /*var win = Windows.FirstOrDefault((w) => w.HWnd == msg.LParam);
                 * if (win == null && msg.LParam == IntPtr.Zero)
                 *  win = SystemWindow.DesktopWindow;*/
                switch (msg.WParam.ToInt32())
                {
                case HSHELL_WINDOWCREATED:
                case HSHELL_WINDOWDESTROYED:
                case HSHELL_WINDOWREPLACING:
                case HSHELL_WINDOWREPLACED:
                    Windows = GetAllToplevelWindows();
                    Debug.WriteLine("Replaced windows " + msg.WParam.ToInt32());
                    FireWindowsChangedEvent();
                    break;

                /*case 32772:
                 *  Windows = GetAllToplevelWindows();
                 *  Debug.WriteLine("Window changed " + msg.WParam.ToInt32());
                 *  FireWindowsChangedEvent();
                 *  break;*/

                /*case HSHELL_WINDOWACTIVATED:
                 * case HSHELL_RUDEAPPACTIVATED:
                 *  Trace.WriteLine("Activated: " + msg.LParam.ToString());
                 *
                 *  if (msg.LParam == IntPtr.Zero)
                 *  {
                 *      break;
                 *  }
                 *
                 *  foreach (var aWin in this.Windows)
                 *  {
                 *      if(aWin.State == ApplicationWindow.WindowState.Active)
                 *          aWin.State = ApplicationWindow.WindowState.Inactive;
                 *  }
                 *
                 *  if (this.Windows.Contains(win))
                 *  {
                 *      GetRealWindow (msg, ref win);
                 *      win.State = ApplicationWindow.WindowState.Active;
                 *  }
                 *  else
                 *  {
                 *      win.State = ApplicationWindow.WindowState.Active;
                 *      if (win.Title != "")
                 *          Windows.Add (win);
                 *  }
                 *  break;
                 *
                 * case HSHELL_FLASH:
                 *  Trace.WriteLine("Flashing window: " + msg.LParam.ToString());
                 *  if (this.Windows.Contains(win))
                 *  {
                 *      GetRealWindow (msg, ref win);
                 *      win.State = ApplicationWindow.WindowState.Flashing;
                 *  }
                 *  else
                 *  {
                 *      win.State = ApplicationWindow.WindowState.Flashing;
                 *      if (win.Title != "")
                 *          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.");
                    NativeMethods.SHELLHOOKINFO winHandle = (NativeMethods.SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(NativeMethods.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.");
                    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.Msg.ToString());
                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception: " + ex.ToString());
                Debugger.Break();
            }
        }
Esempio n. 2
0
        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:
                            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_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());
                            NativeMethods.SHELLHOOKINFO winHandle = (NativeMethods.SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(NativeMethods.SHELLHOOKINFO));
                            winHandle.rc = new NativeMethods.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.OnPropertyChanged("Icon");

                                foreach (ApplicationWindow wind in this.Windows)
                                {
                                    if (wind.WinFileName == win.WinFileName)
                                    {
                                        wind.OnPropertyChanged("ShowInTaskbar");
                                        win.OnPropertyChanged("Title");
                                        win.OnPropertyChanged("Icon");
                                    }
                                }
                            }
                            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.OnPropertyChanged("Icon");
                            }
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Exception: " + ex.ToString());
                    Debugger.Break();
                }
            }
        }