/// <summary>
 /// Makes a window stick
 /// </summary>
 /// <param name="w">the windowinfo of the window</param>
 public static void StickWindow(WindowInfo w)
 {
     if (!IsSticky(w))
         StickyWindows.Add(w);
 }
 /// <summary>
 /// Makes a windows unstick
 /// </summary>
 /// <param name="w">The windowinfo of the window</param>
 public static void UnstickWindow(WindowInfo w)
 {
     if (IsSticky(w))
     {
         WindowInfo delI = null;
         foreach (WindowInfo s in StickyWindows)
         {
             if (s == w)
             {
                 delI = s;
                 break; // TODO: might not be correct. Was : Exit For
             }
         }
         if (delI != null)
             StickyWindows.Remove(delI);
     }
 }
 /// <summary>
 /// Checks if the window is valid
 /// </summary>
 /// <param name="w">The windowinfo of the window<</param>
 /// <param name="includeStickies">A boolean indicating if the sticky
 /// window should be included into the check</param>
 /// <param name="includeHidden">A boolean indicating if hidden windows
 /// should be included in the check</param>
 /// <param name="includeShadows">A boolean indicating if shadow
 /// windows should be included in the check</param>
 /// <returns>A boolean indicating if the window is valid</returns>
 public static bool IsWindowValid(WindowInfo w, bool includeStickies, bool includeHidden, bool includeShadows)
 {
     try
     {
         Regex reg = new Regex("\\*explorer\\*");
         if (WindowManager.IsValid(w)
             && (includeStickies || (!IsSticky(w)))
             && (w.Text != "" || (includeShadows && (w.ClassName == "SysShadow" || w.ClassName == "ShadowWindow")))
             && (includeHidden || w.Visible)
             && (!(w.Handle == WindowManager.FindWindowByClass("Progman").Handle))
             && (!(w.ClassName.ToUpper() == "BUTTON" && (w.Text == "Start" || w.Text == "Démarrer")))
             && (!(System.Diagnostics.Debugger.IsAttached && w.ClassName == "wndclass_desked_gsk"))
             && (AllMonitors || Array.IndexOf(useMons, (Array.IndexOf(Screen.AllScreens, Screen.FromHandle(w.Handle)))) >= 0)
             && w.Width > 0
             && w.Height > 0
             && (!(w.Text == "Start Menu" && reg.IsMatch(w.Process.ProcessName)))
             && (!(w.ClassName == "Desktop User Picture" && reg.IsMatch(w.Process.ProcessName)))
             && (!(w.ClassName == "ThumbnailClass" && reg.IsMatch(w.Process.ProcessName)))
             && (!IsProcessSticky(w.Process.ProcessName)) && (!(w.ProcessId == Process.GetCurrentProcess().Id)))
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch { return true; }
 }
 /// <summary>
 /// Checks if a window is sticky
 /// </summary>
 /// <param name="w">The window info</param>
 /// <returns>A boolean indicating if the window is sticky</returns>
 public static bool IsSticky(WindowInfo w)
 {
     foreach (WindowInfo s in StickyWindows)
     {
         if (s == w)
             return true;
     }
     return false;
 }
 public static void HideWindow(WindowInfo winf)
 {
     foreach (VirtualDesktop d in Desktops)
     {
         foreach (WindowInfo w in d.Windows)
         {
             if ((!object.ReferenceEquals(w, winf)))
                 winf.State = WindowInfo.WindowState.Hide;
         }
     }
 }
 /// <summary>
 /// Checks the validity of a window
 /// </summary>
 /// <param name="w">The windowinfo of the window</param>
 /// <returns>A boolean indicating the validity of the window</returns>
 public static bool IsWindowValid(WindowInfo w)
 {
     return IsWindowValid(w, false);
 }
        public static void ShowOnAllDesktops(WindowInfo w)
        {
            foreach (VirtualDesktop d in VirtualDesktopManager.Desktops)
            {
                try
                {
                    w.State = WindowInfo.WindowState.ShowNA;
                    d.Windows.Add(w);

                }
                catch { }
            }
        }
Пример #8
0
 public void AddToWindowList(WindowInfo winf)
 {
     this.windows.Add(winf);
 }
        public static void SendWindowToDesktop(WindowInfo w, int newDesk, int oldDesk)
        {
            if (oldDesk == newDesk)
                return;
            if (oldDesk == VirtualDesktopManager.CurrentDesktopIndex)
            {
                try
                {
                    VirtualDesktopManager.Desktops[newDesk].Windows.Add(w);
                    if (!w.Minimized && VirtualDesktopManager.IsProcessMinimizing(w.Process.ProcessName))
                    {
                        w.State = WindowInfo.WindowState.Minimize;
                        w.BringToFront();
                        VirtualDesktopManager.Desktops[newDesk].WindowsToRestore.Add(w);
                    }
                    w.State = WindowInfo.WindowState.Hide;

                }
                catch {}
            }
            else if (newDesk == VirtualDesktopManager.CurrentDesktopIndex)
            {
                try
                {
                    w.State = WindowInfo.WindowState.ShowNA;
                    if (VirtualDesktopManager.Desktops[oldDesk].WindowsToRestore.Contains(w))
                        w.State = WindowInfo.WindowState.Restore;
                    VirtualDesktopManager.Desktops[oldDesk].RemoveAllInstances(w);

                }
                catch{}
            }
            else
            {
                VirtualDesktopManager.Desktops[newDesk].Windows.Add(w);
                if (VirtualDesktopManager.Desktops[oldDesk].WindowsToRestore.Contains(w))
                {
                    VirtualDesktopManager.Desktops[newDesk].WindowsToRestore.Add(w);
                }
                VirtualDesktopManager.Desktops[oldDesk].RemoveAllInstances(w);
            }
        }
Пример #10
0
 public static void SendWindowToDesktop(WindowInfo w, int newDesk)
 {
    int sourceDesk = FindSourceDesk(w);
    if(sourceDesk!=-1)
    {
         SendWindowToDesktop(w, newDesk,sourceDesk);
    }
 }
Пример #11
0
 public static bool IsValid(WindowInfo w)
 {
     return User32.IsWindow(w.Handle);
 }
Пример #12
0
        private void ShellWinProc(ref Message m)
        {
            try
            {
                if (m.Msg == WM_SHELLHOOKMESSAGE)
                {
                    switch ((ShellMessages)m.WParam)
                    {
                        case ShellMessages.HSHELL_WINDOWCREATED:
                            if (WindowManager.IsValid(m.LParam))
                                if (WindowCreated != null)
                                {
                                    WindowCreated(new WindowInfo(m.LParam));
                                    Console.WriteLine(m.LParam.ToString());
                                }

                            break;
                        case ShellMessages.HSHELL_WINDOWDESTROYED:
                            if (WindowManager.IsValid(m.LParam))
                                if (WindowDestroyed != null)
                                {
                                    WindowDestroyed(m.LParam);
                                }

                            break;
                        case ShellMessages.HSHELL_WINDOWREPLACING:
                            replacingWindow = m.LParam;
                            break;
                        case ShellMessages.HSHELL_WINDOWREPLACED:
                            if (WindowManager.IsValid(replacingWindow) && WindowManager.IsValid(m.LParam))
                                if (WindowReplaced != null)
                                {
                                    WindowReplaced(new WindowInfo(replacingWindow), new WindowInfo(m.LParam));
                                }

                            break;
                        case ShellMessages.HSHELL_WINDOWACTIVATED:
                            if (WindowManager.IsValid(m.LParam))
                                if (WindowActivated != null)
                                {
                                    WindowActivated(new WindowInfo(m.LParam), false);
                                }

                            break;
                        case ShellMessages.HSHELL_FLASH:
                            if (WindowManager.IsValid(m.LParam))
                                if (WindowTitleChange != null)
                                {
                                    WindowTitleChange(new WindowInfo(m.LParam), true);
                                }

                            break;
                        case ShellMessages.HSHELL_RUDEAPPACTIVATED:
                            if (WindowManager.IsValid(m.LParam))
                                if (WindowActivated != null)
                                {
                                    WindowActivated(new WindowInfo(m.LParam), false);
                                }

                            break;
                        case ShellMessages.HSHELL_REDRAW:
                            if (WindowManager.IsValid(m.LParam))
                                if (WindowTitleChange != null)
                                {
                                    WindowTitleChange(new WindowInfo(m.LParam), false);
                                }

                            break;
                        case ShellMessages.HSHELL_APPCOMMAND:
                            bool cancel = false;
                            if (ApplicationCommand != null)
                            {
                                ApplicationCommand(null, (ApplicationCommandType)(Convert.ToInt32(m.LParam) >> 8), ref cancel);
                            }
                            break;
                        case ShellMessages.HSHELL_ACTIVATESHELLWINDOW:
                            if (ActivateShellWindow != null)
                            {
                                ActivateShellWindow();
                            }

                            break;
                        case ShellMessages.HSHELL_TASKMAN:
                            cancel = false;
                            if (OpenTaskManager != null)
                            {
                                OpenTaskManager(ref cancel);
                            }

                            break;
                        case ShellMessages.HSHELL_GETMINRECT:
                            SHELLHOOKINFO winHandle = (SHELLHOOKINFO)Marshal.PtrToStructure(m.LParam, typeof(SHELLHOOKINFO));
                            //Dim ptr As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf(GetType(RECT)))
                            //Marshal.StructureToPtr(winHandle.rc, ptr, True)
                            //m.Result = ShellProc(HSHELL_GETMINRECT, winHandle.hwnd, ptr)
                            //winHandle.rc = Marshal.PtrToStructure(ptr, GetType(RECT))
                            //winHandle.rc = New RECT
                            WindowInfo wi = new WindowInfo(winHandle.hwnd);
                            winHandle.rc.top = 0;
                            winHandle.rc.left = 0;
                            winHandle.rc.right = 100;
                            winHandle.rc.bottom = 100;
                            Marshal.StructureToPtr(winHandle, m.LParam, true);
                            m.Result = winHandle.hwnd;
                            break;
                        //Marshal.FreeHGlobal(ptr)
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Print("An error occured in ShellWinProc: " + ex.Message);
            }
        }
Пример #13
0
 /// <summary>
 /// Removes all instances of a window
 /// </summary>
 /// <param name="rw">Windowinfo of the window that needs to be removed</param>
 public void RemoveAllInstances(WindowInfo rw)
 {
     lock (windows)
     {
         System.Collections.ObjectModel.Collection<WindowInfo> remItems = new System.Collections.ObjectModel.Collection<WindowInfo>();
         foreach (WindowInfo w in windows)
         {
             if (w == rw)
             {
                 remItems.Add(w);
             }
         }
         foreach (WindowInfo w in windowsRestore)
         {
             if (w == rw)
             {
                 remItems.Add(w);
             }
         }
         foreach (WindowInfo w in remItems)
         {
             this.windows.Remove(w);
         }
     }
 }
Пример #14
0
 public bool IsChild(WindowInfo parent)
 {
     return User32.IsChild(parent.Handle, hWnd);
 }
Пример #15
0
 private static int FindSourceDesk(WindowInfo w)
 {
     for(int i=0;i<VirtualDesktopManager.Desktops.Count;i++)
     {
         VirtualDesktop d = VirtualDesktopManager.Desktops[i];
         foreach (WindowInfo winf in d.Windows)
         {
             if (w.ProcessId == winf.ProcessId)
                 return i;
         }
     }
     return -1;
 }
Пример #16
0
 public bool IsParent(WindowInfo child)
 {
     return User32.IsChild(hWnd, child.Handle);
 }
Пример #17
0
 /// <summary>
 /// Validates a window that needs to be hidden
 /// </summary>
 /// <param name="w">The windoinfo of the window that needs to be validated</param>
 /// <returns>A boolean indicating the validity of the window</returns>
 protected bool HideWindowValid(WindowInfo w)
 {
     return VirtualDesktopManager.IsWindowValid(w, false, false, true);
 }