Exemplo n.º 1
0
        //private static bool IsPopup(IntPtr hWnd)
        //{
        //    StringBuilder buff = new StringBuilder(256);
        //    Win32.GetClassName(hWnd, buff, 256);
        //    string wndName = buff.ToString();

        //    int wndStyle = Win32.GetWindowLong(hWnd, Win32.GWL_STYLE);
        //    int wndExStyle = Win32.GetWindowLong(hWnd, Win32.GWL_EXSTYLE);

        //    bool isPopup = (wndStyle & Win32.WS_POPUP) != 0;
        //    bool isTooWnd = (wndExStyle & Win32.WS_EX_TOOLWINDOW) != 0;
        //    bool isWindow = Win32.IsWindow(hWnd);
        //    Debug.WriteLine("ClassName: " + wndName + " IsPopup : " + isPopup + " IsToolWnd: " + isTooWnd + " IsWindow: " + isWindow);
        //    return false;
        //}

        /// <summary>
        /// Check if window handle is visible opened window which should be minimized
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private static bool EnumWindowsProc(IntPtr hWnd, int lParam)
        {
            Win32.WINDOWPLACEMENT placement = new Win32.WINDOWPLACEMENT();
            placement.length = System.Runtime.InteropServices.Marshal.SizeOf(placement);
            Win32.GetWindowPlacement(hWnd, ref placement);


            StringBuilder buff    = new StringBuilder(256);
            IntPtr        mainWnd = Win32.GetAncestor(hWnd, Win32.GA_ROOT);

            int wndExStyle = Win32.GetWindowLong(hWnd, Win32.GWL_EXSTYLE);

            Win32.GetClassName(mainWnd, buff, 256);
            string className = buff.ToString();

            if (mainWnd != IntPtr.Zero &&
                Win32.IsWindowVisible(mainWnd) &&
                placement.showCmd != Win32.SW_SHOWMINIMIZED &&
                placement.showCmd != Win32.SW_MINIMIZE &&
                ((wndExStyle & ~Win32.WS_EX_TOOLWINDOW) == wndExStyle) && // is not tool window
                !AppGroupOptions.IsDesktop(className) &&
                !AppGroupOptions.IsTaskbar(className) &&
                !m_openedWnds.Contains(mainWnd)
                )
            {
                Win32.GetWindowText(mainWnd, buff, 256);
                string wndText = buff.ToString();
                Debug.WriteLine("ADD: " + wndText + " " + placement.showCmd);

                m_openedWnds.Add(hWnd);
            }
            return(true);
        }
Exemplo n.º 2
0
        bool maximized(IntPtr hwnd)
        {
            Win32.WINDOWPLACEMENT placement = new Win32.WINDOWPLACEMENT();
            if (!Win32.GetWindowPlacement(Handle, ref placement))
            {
                return(false);
            }

            return(placement.showCmd == Win32.SW_MAXIMIZE);
        }
Exemplo n.º 3
0
        static void HideWindow(IntPtr hWnd)
        {
            Win32.WINDOWPLACEMENT wp = new Win32.WINDOWPLACEMENT();
            Win32.GetWindowPlacement(hWnd, ref wp);

            // Hide (close) window only if still minimized
            if ((wp.showCmd == Win32.SW_MINIMIZE) || (wp.showCmd == Win32.SW_SHOWMINIMIZED))
            {
                Win32.SendMessage(hWnd, Win32.WM_CLOSE, 0, 0);
            }
        }
Exemplo n.º 4
0
        private void BringWindowToTop(ProcessItem processItem)
        {
            var winPlacement = new Win32.WINDOWPLACEMENT();

            Win32.GetWindowPlacement(processItem.WindowHandle, ref winPlacement);

            Debug.WriteLine($"activating pid:{processItem.Id}, hWnd:{processItem.WindowHandle.ToHex()}");

            if (winPlacement.WindowState == Win32.WindowState.Minimized)
            {
                Win32.RestoreWindow(processItem.WindowHandle);
            }
            else
            {
                Win32.ShowWindow(processItem.WindowHandle);
            }

            Win32.BringWindowToTop(processItem.WindowHandle);
            Win32.SetForegroundWindow(processItem.WindowHandle);

            processItem.LastUsed = DateTime.Now;
        }
Exemplo n.º 5
0
        public override void ExecuteAction(IntPtr activeWnd, Point location)
        {
            if (m_wndFullscreen == null) m_wndFullscreen = new Dictionary<IntPtr, Win32.WINDOWINFO>();
            if (m_wndTray == null) m_wndTray = new Dictionary<IntPtr, Win32.WINDOWINFO>();
            if (m_wndTopMost == null) m_wndTopMost = new List<IntPtr>();
            if (m_openedWnds == null) m_openedWnds = new List<IntPtr>();
            
            StringBuilder buff = new StringBuilder(256);
            Win32.GetClassName(activeWnd, buff, 256);
            Debug.WriteLine(buff.ToString());
            string wndName = buff.ToString();//.ToUpper();
            if ((AppGroupOptions.IsDesktop(wndName) || AppGroupOptions.IsTaskbar(wndName)) 
                && (this.Name != WND_MIN_ALL && this.Name != WND_CLOSE_ALL && this.Name != WND_SHOW_SIDE_BY_SIDE
                && this.Name != WND_SHOW_VERTICALLY))
                return;
            //Win32.GetWindowText(ActiveWnd, buff, 256);            

            int x1, x2, y1, y2;
            Win32.WINDOWINFO info = new Win32.WINDOWINFO();
            Rectangle screen;
            info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
            Win32.WINDOWPLACEMENT placement = new Win32.WINDOWPLACEMENT();
            placement.length = System.Runtime.InteropServices.Marshal.SizeOf(placement);

            IntPtr hwndTaskbar = Win32.FindWindow(AppGroupOptions.SYSTEM_TASKBAR, null);            
            switch (this.Name)
            {
                case WND_MIN:
                    Win32.SendMessage(activeWnd, Win32.WM_SYSCOMMAND, Win32.SC_MINIMIZE, 0);                    
                    break;
                case WND_MIN_ALL:
                    List<IntPtr> opendedWnds = new List<IntPtr>(m_openedWnds);
                    m_openedWnds = new List<IntPtr>();
                    Win32.EnumDelegate enumfunc = new Win32.EnumDelegate(EnumWindowsProc);
                    IntPtr hDesktop = IntPtr.Zero; // current desktop
                    bool success = Win32.EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero);
                    if (success)
                    {
                        if (m_openedWnds.Count == 0)
                        {
                            opendedWnds.Reverse();
                            foreach (IntPtr hwnd in opendedWnds)
                                Win32.SendMessage(hwnd, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0);
                                //Win32.SetWindowPos(hwnd, Win32.HWND_NOTOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW);
                        }
                        else
                        {
                            foreach (IntPtr hwnd in m_openedWnds)
                                Win32.SendMessage(hwnd, Win32.WM_SYSCOMMAND, Win32.SC_MINIMIZE, 0);
                        }
                    }
                //Win32.SendMessage(hwndTaskbar, Win32.WM_COMMAND, Win32.WINS_MIN_ALL, 0);
                    break;
                case WND_MIN_TOTRAY:
                    StringBuilder title = new StringBuilder(256);
                    Win32.GetWindowText(activeWnd, title, 256);
                    Emptydel del = delegate()
                    {
                        Win32.GetWindowInfo(activeWnd, ref info);
                        if (m_wndTray.ContainsKey(activeWnd))
                            m_wndTray[activeWnd] = info;
                        else
                        {
                            m_wndTray.Add(activeWnd, info);
                            NotifyIcon tray = new NotifyIcon();
                            //tray = new NotifyIcon();                    
                            tray.Visible = true;
                            tray.Tag = activeWnd;
                            tray.Icon = GetWindowIcon(activeWnd);
                            tray.Text = title.Length >= 64 ? title.ToString().Substring(0, 60) + "..." : title.ToString();
                            tray.Click += new EventHandler(tray_Click);
                            Form_engine.TrayIcons.Add(tray);
                        }
                        Win32.ShowWindow(activeWnd, 0);//hide
                    };
                    Form_engine.Instance.Invoke(del);
                    //if (string.IsNullOrEmpty(title.ToString()))
                    //    return;
                    break;
                case WND_MAX:
                    Win32.GetWindowPlacement(activeWnd, ref placement);
                    if (placement.showCmd == Win32.SW_SHOWNORMAL)
                        Win32.SendMessage(activeWnd, Win32.WM_SYSCOMMAND, Win32.SC_MAXIMIZE, 0);
                    else if (placement.showCmd == Win32.SW_SHOWMAXIMIZED)
                        Win32.SendMessage(activeWnd, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0);
                    break;
                case WND_CLOSE:
                    //Win32.PostMessage(ActiveWnd, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE, 0);
                    Win32.PostMessage(activeWnd, Win32.WM_CLOSE, 0, 0);
                    break;
                case WND_CLOSE_ALL:
                    int jgProcessId = Form_engine.Instance.ProcessId;
                    foreach (Process p in Process.GetProcesses(System.Environment.MachineName))
                    {
                        if (p.Id != jgProcessId)
                        {
                            // some application which aren't system might have handle zero but still has to be closed! fix is required
                            if (p.MainWindowHandle != IntPtr.Zero)
                                p.CloseMainWindow();
                        }
                    }      
                    break;
                case WND_FULL_SCREEN:
                    screen = Screen.FromHandle(activeWnd).Bounds;
                    Win32.GetWindowInfo(activeWnd, ref info);
                    
                    int style = (int)info.dwStyle;
                    int fullscreen_style = (int)info.dwStyle & ~Win32.WS_CAPTION & ~Win32.WS_THICKFRAME;

                    //RETURN_TO_NORMAL
                    if ((info.rcWindow.left == screen.Left && info.rcWindow.top == screen.Top &&
                        info.rcWindow.right == screen.Right && info.rcWindow.bottom == screen.Bottom
                        && style == fullscreen_style) || m_wndFullscreen.ContainsKey(activeWnd))
                    {
                        goto case WND_RETURN_TO_NORMAL;                     
                    }
                    //MAKE_FULL_SCREEN
                    else
                    {
                        m_wndFullscreen.Add(activeWnd, info);
                        Win32.SetWindowLong(activeWnd, Win32.GWL_STYLE, ((int)info.dwStyle & ~Win32.WS_CAPTION & ~Win32.WS_THICKFRAME));
                        //Win32.SetWindowLong(ActiveWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_TOOLWINDOW);
                        Win32.SetWindowPos(activeWnd, Win32.HWND_TOPMOST, screen.Left, screen.Top, screen.Width, screen.Height, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                        //Win32.SetWindowPos(ActiveWnd, Win32.HWND_TOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                        //Win32.MoveWindow(ActiveWnd, x1, y1, info.rcWindow.right - info.rcWindow.left, info.rcWindow.bottom - info.rcWindow.top, true);
                        //Win32.MoveWindow(ActiveWnd, x1, y1, x2, y2, true);                    
                        //Win32.InvalidateRect(ActiveWnd, ref info.rcWindow, true);
                        //Win32.UpdateWindow(ActiveWnd);                    
                    }
                    break;
                case WND_RETURN_TO_NORMAL:
                    if (m_wndFullscreen.ContainsKey(activeWnd))
                    {
                        info = m_wndFullscreen[activeWnd];
                        x1 = info.rcWindow.left;
                        y1 = info.rcWindow.top;
                        x2 = info.rcWindow.right - x1;
                        y2 = info.rcWindow.bottom - y1;
                        Win32.SetWindowLong(activeWnd, Win32.GWL_STYLE, (int)info.dwStyle);
                        Win32.SetWindowLong(activeWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_LAYERED);
                        //Win32.SendMessage(ActiveWnd, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0);
                        Win32.SetWindowPos(activeWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                        m_wndFullscreen.Remove(activeWnd);
                    }
                    else
                    {
                        screen = Screen.FromHandle(activeWnd).Bounds;
                        x1 = screen.Left + (int)(screen.Width * (1 - WND_DEFAUL_RATIO)) / 2;
                        y1 = screen.Top + (int)(screen.Height * (1 - WND_DEFAUL_RATIO)) / 2;
                        x2 = (int)Math.Floor(screen.Width * WND_DEFAUL_RATIO);
                        y2 = (int)Math.Floor(screen.Height * WND_DEFAUL_RATIO);

                        Win32.SetWindowLong(activeWnd, Win32.GWL_STYLE, (int)info.dwStyle | Win32.WS_CAPTION | Win32.WS_THICKFRAME);
                        Win32.SetWindowLong(activeWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_LAYERED);
                        //Win32.RedrawWindow(ActiveWnd, ref info.rcWindow, IntPtr.Zero, Win32.RDW_ERASE | Win32.RDW_INVALIDATE | Win32.RDW_FRAME | Win32.RDW_ALLCHILDREN);                        
                        Win32.SetWindowPos(activeWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                        
                    }
                    break;
                case WND_TOP_MOST:
                    Win32.GetWindowInfo(activeWnd, ref info);
                    x1 = info.rcWindow.left;
                    y1 = info.rcWindow.top;
                    x2 = info.rcWindow.right - x1;
                    y2 = info.rcWindow.bottom - y1;
                    if (!m_wndTopMost.Contains(activeWnd))
                    {
                        m_wndTopMost.Add(activeWnd);
                        Win32.SetWindowPos(activeWnd, Win32.HWND_TOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW);
                    }
                    else
                    {
                        m_wndTopMost.Remove(activeWnd);
                        Win32.SetWindowPos(activeWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW);
                    }
                       
                    break;                
                case WND_TRANSPARENT:
                    SetWindowTrasparency(activeWnd, Int16.Parse(this.Details));
                    break;
                case WND_SHOW_VERTICALLY:
                    Win32.SendMessage(hwndTaskbar, Win32.WM_COMMAND, Win32.WINS_ARRANGE_VRT, 0);
                    break;
                case WND_SHOW_SIDE_BY_SIDE:
                    Win32.SendMessage(hwndTaskbar, Win32.WM_COMMAND, Win32.WINS_ARRANGE_HRZ, 0);
                    break;
                case WND_REDRAWN:
                    Win32.InvalidateRgn(activeWnd, IntPtr.Zero, true);
                    //Win32.GetWindowInfo(ActiveWnd, ref info);
                    //x1 = info.rcWindow.left;
                    //y1 = info.rcWindow.top;
                    //x2 = info.rcWindow.right - x1;
                    //y2 = info.rcWindow.bottom - y1;

                    //IntPtr screenDc = Win32.GetDC(IntPtr.Zero);
                    //IntPtr memDc = Win32.CreateCompatibleDC(screenDc);
                    //Win32.SIZE size = new Win32.SIZE(Math.Abs(x2 - x1), Math.Abs(y2 - y1));

                    //Win32.POINT pointSource = new Win32.POINT(x1,y1);
                    //Win32.POINT topPos = new Win32.POINT(x1, y1);

                    //Win32.BLENDFUNCTION blend = new Win32.BLENDFUNCTION();
                    //blend.BlendOp = 0;
                    //blend.BlendFlags = 0;
                    //blend.SourceConstantAlpha = 122;
                    //blend.AlphaFormat = 1;

                    //Win32.UpdateLayeredWindow(ActiveWnd, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32.ULW_ALPHA);

                    ////Win32.InvalidateRect(ActiveWnd, ref info.rcWindow, true);
                    ////Win32.MoveWindow(ActiveWnd, x1, y1, x2 - 10, y2 - 10, true);
                    ////Win32.UpdateWindow(ActiveWnd);
                    ////Win32.SetWindowPos(ActiveWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_FRAMECHANGED);
                    //Win32.ReleaseDC(IntPtr.Zero, screenDc);
                    //Win32.DeleteDC(memDc);
                    break;
            }
        }
Exemplo n.º 6
0
        //private static bool IsPopup(IntPtr hWnd)
        //{
        //    StringBuilder buff = new StringBuilder(256);
        //    Win32.GetClassName(hWnd, buff, 256);
        //    string wndName = buff.ToString();

        //    int wndStyle = Win32.GetWindowLong(hWnd, Win32.GWL_STYLE);
        //    int wndExStyle = Win32.GetWindowLong(hWnd, Win32.GWL_EXSTYLE);

        //    bool isPopup = (wndStyle & Win32.WS_POPUP) != 0;
        //    bool isTooWnd = (wndExStyle & Win32.WS_EX_TOOLWINDOW) != 0;
        //    bool isWindow = Win32.IsWindow(hWnd);
        //    Debug.WriteLine("ClassName: " + wndName + " IsPopup : " + isPopup + " IsToolWnd: " + isTooWnd + " IsWindow: " + isWindow);
        //    return false;
        //}

        /// <summary>
        /// Check if window handle is visible opened window which should be minimized
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private static bool EnumWindowsProc(IntPtr hWnd, int lParam)
        {
            Win32.WINDOWPLACEMENT placement = new Win32.WINDOWPLACEMENT();
            placement.length = System.Runtime.InteropServices.Marshal.SizeOf(placement);            
            Win32.GetWindowPlacement(hWnd, ref placement);


            StringBuilder buff = new StringBuilder(256);
            IntPtr mainWnd = Win32.GetAncestor(hWnd, Win32.GA_ROOT);

            int wndExStyle = Win32.GetWindowLong(hWnd, Win32.GWL_EXSTYLE);

            Win32.GetClassName(mainWnd, buff, 256);
            string className = buff.ToString();

            if (mainWnd != IntPtr.Zero 
                && Win32.IsWindowVisible(mainWnd)   
                && placement.showCmd != Win32.SW_SHOWMINIMIZED
                && placement.showCmd != Win32.SW_MINIMIZE
                && ((wndExStyle & ~Win32.WS_EX_TOOLWINDOW) == wndExStyle) // is not tool window
                && !AppGroupOptions.IsDesktop(className)
                && !AppGroupOptions.IsTaskbar(className)
                && !m_openedWnds.Contains(mainWnd)
                )
            {
                Win32.GetWindowText(mainWnd, buff, 256);
                string wndText = buff.ToString();
                Debug.WriteLine("ADD: " + wndText + " " + placement.showCmd);

                m_openedWnds.Add(hWnd);
            }
            return true;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Send mouse click to relative position in the client window.
        /// </summary>
        /// <param name="client">Target client.</param>
        /// <param name="button">System.Windows.Forms.MouseButtons to click.</param>
        /// <param name="x">X position of point to click relative to client window's X position.</param>
        /// <param name="y">Y position of point to click relative to client window's Y position.</param>
        /// <param name="doubleClick">True for double click, false for single click.</param>
        /// <returns>True on success.</returns>
        public static bool SendMouseClick(int client, MouseButtons button, int x, int y, bool doubleClick)
        {
            ClientInfo ci;

            if (ClientInfoCollection.GetClient(client, out ci))
            {
                Win32.INPUT[]    inputs = new Win32.INPUT[2];
                Win32.MOUSEINPUT mi     = new Win32.MOUSEINPUT();
                inputs[0].type = Win32.INPUT_MOUSE;
                inputs[1].type = Win32.INPUT_MOUSE;
                mi.dx          = 0;
                mi.dy          = 0;
                switch (button)
                {
                case MouseButtons.None:
                    return(false);

                case MouseButtons.Left:
                    mi.dwFlags        = Win32.MOUSEEVENTF_LEFTDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = Win32.MOUSEEVENTF_LEFTUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.Right:
                    mi.dwFlags        = Win32.MOUSEEVENTF_RIGHTDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = Win32.MOUSEEVENTF_RIGHTUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.Middle:
                    mi.dwFlags        = Win32.MOUSEEVENTF_MIDDLEDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = Win32.MOUSEEVENTF_MIDDLEUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.XButton1:
                    mi.mouseData      = Win32.XBUTTON1;
                    mi.dwFlags        = Win32.MOUSEEVENTF_XDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = Win32.MOUSEEVENTF_XUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.XButton2:
                    mi.mouseData      = Win32.XBUTTON2;
                    mi.dwFlags        = Win32.MOUSEEVENTF_XDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = Win32.MOUSEEVENTF_XUP;
                    inputs[1].mkhi.mi = mi;
                    break;
                }

                if (!ci.PrepareWindowForInput())
                {
                    ci.DetachFromWindow();
                    return(false);
                }

                Win32.WINDOWPLACEMENT wp = new Win32.WINDOWPLACEMENT();
                if (Win32.GetWindowPlacement(ci.WindowHandle, ref wp))
                {
                    /*int screenX = wp.rcNormalPosition.X + x;
                     * int screenY = wp.rcNormalPosition.Y + y;
                     * int absX = (screenX * 65536 / Screen.PrimaryScreen.Bounds.Width);
                     * int absY = (screenY * 65536 / Screen.PrimaryScreen.Bounds.Height);
                     * inputs[0].mkhi.mi.dx = absX;
                     * inputs[1].mkhi.mi.dx = absX;
                     * inputs[0].mkhi.mi.dy = absY;
                     * inputs[1].mkhi.mi.dy = absY;*/

                    // using this method because absolute position is always off by a pixel or 2

                    if (!Win32.SetCursorPos(x + wp.rcNormalPosition.X, y + wp.rcNormalPosition.Y))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                uint success = Win32.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(inputs[0]));
                if (doubleClick && success == inputs.Length)
                {
                    success = Win32.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(inputs[0]));
                }
                ci.DetachFromWindow();
                return(success == inputs.Length);
            }
            return(false);
        }
Exemplo n.º 8
0
        public override void ExecuteAction(IntPtr activeWnd, Point location)
        {
            if (m_wndFullscreen == null)
            {
                m_wndFullscreen = new Dictionary <IntPtr, Win32.WINDOWINFO>();
            }
            if (m_wndTray == null)
            {
                m_wndTray = new Dictionary <IntPtr, Win32.WINDOWINFO>();
            }
            if (m_wndTopMost == null)
            {
                m_wndTopMost = new List <IntPtr>();
            }
            if (m_openedWnds == null)
            {
                m_openedWnds = new List <IntPtr>();
            }

            StringBuilder buff = new StringBuilder(256);

            Win32.GetClassName(activeWnd, buff, 256);
            Debug.WriteLine(buff.ToString());
            string wndName = buff.ToString();//.ToUpper();

            if ((AppGroupOptions.IsDesktop(wndName) || AppGroupOptions.IsTaskbar(wndName)) &&
                (this.Name != WND_MIN_ALL && this.Name != WND_CLOSE_ALL && this.Name != WND_SHOW_SIDE_BY_SIDE &&
                 this.Name != WND_SHOW_VERTICALLY))
            {
                return;
            }
            //Win32.GetWindowText(ActiveWnd, buff, 256);

            int x1, x2, y1, y2;

            Win32.WINDOWINFO info = new Win32.WINDOWINFO();
            Rectangle        screen;

            info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
            Win32.WINDOWPLACEMENT placement = new Win32.WINDOWPLACEMENT();
            placement.length = System.Runtime.InteropServices.Marshal.SizeOf(placement);

            IntPtr hwndTaskbar = Win32.FindWindow(AppGroupOptions.SYSTEM_TASKBAR, null);

            switch (this.Name)
            {
            case WND_MIN:
                Win32.SendMessage(activeWnd, Win32.WM_SYSCOMMAND, Win32.SC_MINIMIZE, 0);
                break;

            case WND_MIN_ALL:
                List <IntPtr> opendedWnds = new List <IntPtr>(m_openedWnds);
                m_openedWnds = new List <IntPtr>();
                Win32.EnumDelegate enumfunc = new Win32.EnumDelegate(EnumWindowsProc);
                IntPtr             hDesktop = IntPtr.Zero; // current desktop
                bool success = Win32.EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero);
                if (success)
                {
                    if (m_openedWnds.Count == 0)
                    {
                        opendedWnds.Reverse();
                        foreach (IntPtr hwnd in opendedWnds)
                        {
                            Win32.SendMessage(hwnd, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0);
                        }
                        //Win32.SetWindowPos(hwnd, Win32.HWND_NOTOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW);
                    }
                    else
                    {
                        foreach (IntPtr hwnd in m_openedWnds)
                        {
                            Win32.SendMessage(hwnd, Win32.WM_SYSCOMMAND, Win32.SC_MINIMIZE, 0);
                        }
                    }
                }
                //Win32.SendMessage(hwndTaskbar, Win32.WM_COMMAND, Win32.WINS_MIN_ALL, 0);
                break;

            case WND_MIN_TOTRAY:
                StringBuilder title = new StringBuilder(256);
                Win32.GetWindowText(activeWnd, title, 256);
                Emptydel del = delegate()
                {
                    Win32.GetWindowInfo(activeWnd, ref info);
                    if (m_wndTray.ContainsKey(activeWnd))
                    {
                        m_wndTray[activeWnd] = info;
                    }
                    else
                    {
                        m_wndTray.Add(activeWnd, info);
                        NotifyIcon tray = new NotifyIcon();
                        //tray = new NotifyIcon();
                        tray.Visible = true;
                        tray.Tag     = activeWnd;
                        tray.Icon    = GetWindowIcon(activeWnd);
                        tray.Text    = title.Length >= 64 ? title.ToString().Substring(0, 60) + "..." : title.ToString();
                        tray.Click  += new EventHandler(tray_Click);
                        Form_engine.TrayIcons.Add(tray);
                    }
                    Win32.ShowWindow(activeWnd, 0);    //hide
                };
                Form_engine.Instance.Invoke(del);
                //if (string.IsNullOrEmpty(title.ToString()))
                //    return;
                break;

            case WND_MAX:
                Win32.GetWindowPlacement(activeWnd, ref placement);
                if (placement.showCmd == Win32.SW_SHOWNORMAL)
                {
                    Win32.SendMessage(activeWnd, Win32.WM_SYSCOMMAND, Win32.SC_MAXIMIZE, 0);
                }
                else if (placement.showCmd == Win32.SW_SHOWMAXIMIZED)
                {
                    Win32.SendMessage(activeWnd, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0);
                }
                break;

            case WND_CLOSE:
                //Win32.PostMessage(ActiveWnd, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE, 0);
                Win32.PostMessage(activeWnd, Win32.WM_CLOSE, 0, 0);
                break;

            case WND_CLOSE_ALL:
                int jgProcessId = Form_engine.Instance.ProcessId;
                foreach (Process p in Process.GetProcesses(System.Environment.MachineName))
                {
                    if (p.Id != jgProcessId)
                    {
                        // some application which aren't system might have handle zero but still has to be closed! fix is required
                        if (p.MainWindowHandle != IntPtr.Zero)
                        {
                            p.CloseMainWindow();
                        }
                    }
                }
                break;

            case WND_FULL_SCREEN:
                screen = Screen.FromHandle(activeWnd).Bounds;
                Win32.GetWindowInfo(activeWnd, ref info);

                int style            = (int)info.dwStyle;
                int fullscreen_style = (int)info.dwStyle & ~Win32.WS_CAPTION & ~Win32.WS_THICKFRAME;

                //RETURN_TO_NORMAL
                if ((info.rcWindow.left == screen.Left && info.rcWindow.top == screen.Top &&
                     info.rcWindow.right == screen.Right && info.rcWindow.bottom == screen.Bottom &&
                     style == fullscreen_style) || m_wndFullscreen.ContainsKey(activeWnd))
                {
                    goto case WND_RETURN_TO_NORMAL;
                }
                //MAKE_FULL_SCREEN
                else
                {
                    m_wndFullscreen.Add(activeWnd, info);
                    Win32.SetWindowLong(activeWnd, Win32.GWL_STYLE, ((int)info.dwStyle & ~Win32.WS_CAPTION & ~Win32.WS_THICKFRAME));
                    //Win32.SetWindowLong(ActiveWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_TOOLWINDOW);
                    Win32.SetWindowPos(activeWnd, Win32.HWND_TOPMOST, screen.Left, screen.Top, screen.Width, screen.Height, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                    //Win32.SetWindowPos(ActiveWnd, Win32.HWND_TOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                    //Win32.MoveWindow(ActiveWnd, x1, y1, info.rcWindow.right - info.rcWindow.left, info.rcWindow.bottom - info.rcWindow.top, true);
                    //Win32.MoveWindow(ActiveWnd, x1, y1, x2, y2, true);
                    //Win32.InvalidateRect(ActiveWnd, ref info.rcWindow, true);
                    //Win32.UpdateWindow(ActiveWnd);
                }
                break;

            case WND_RETURN_TO_NORMAL:
                if (m_wndFullscreen.ContainsKey(activeWnd))
                {
                    info = m_wndFullscreen[activeWnd];
                    x1   = info.rcWindow.left;
                    y1   = info.rcWindow.top;
                    x2   = info.rcWindow.right - x1;
                    y2   = info.rcWindow.bottom - y1;
                    Win32.SetWindowLong(activeWnd, Win32.GWL_STYLE, (int)info.dwStyle);
                    Win32.SetWindowLong(activeWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_LAYERED);
                    //Win32.SendMessage(ActiveWnd, Win32.WM_SYSCOMMAND, Win32.SC_RESTORE, 0);
                    Win32.SetWindowPos(activeWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                    m_wndFullscreen.Remove(activeWnd);
                }
                else
                {
                    screen = Screen.FromHandle(activeWnd).Bounds;
                    x1     = screen.Left + (int)(screen.Width * (1 - WND_DEFAUL_RATIO)) / 2;
                    y1     = screen.Top + (int)(screen.Height * (1 - WND_DEFAUL_RATIO)) / 2;
                    x2     = (int)Math.Floor(screen.Width * WND_DEFAUL_RATIO);
                    y2     = (int)Math.Floor(screen.Height * WND_DEFAUL_RATIO);

                    Win32.SetWindowLong(activeWnd, Win32.GWL_STYLE, (int)info.dwStyle | Win32.WS_CAPTION | Win32.WS_THICKFRAME);
                    Win32.SetWindowLong(activeWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_LAYERED);
                    //Win32.RedrawWindow(ActiveWnd, ref info.rcWindow, IntPtr.Zero, Win32.RDW_ERASE | Win32.RDW_INVALIDATE | Win32.RDW_FRAME | Win32.RDW_ALLCHILDREN);
                    Win32.SetWindowPos(activeWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW | Win32.SWP_DRAWFRAME | Win32.SWP_FRAMECHANGED);
                }
                break;

            case WND_TOP_MOST:
                Win32.GetWindowInfo(activeWnd, ref info);
                x1 = info.rcWindow.left;
                y1 = info.rcWindow.top;
                x2 = info.rcWindow.right - x1;
                y2 = info.rcWindow.bottom - y1;
                if (!m_wndTopMost.Contains(activeWnd))
                {
                    m_wndTopMost.Add(activeWnd);
                    Win32.SetWindowPos(activeWnd, Win32.HWND_TOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW);
                }
                else
                {
                    m_wndTopMost.Remove(activeWnd);
                    Win32.SetWindowPos(activeWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW);
                }

                break;

            case WND_TRANSPARENT:
                SetWindowTrasparency(activeWnd, Int16.Parse(this.Details));
                break;

            case WND_SHOW_VERTICALLY:
                Win32.SendMessage(hwndTaskbar, Win32.WM_COMMAND, Win32.WINS_ARRANGE_VRT, 0);
                break;

            case WND_SHOW_SIDE_BY_SIDE:
                Win32.SendMessage(hwndTaskbar, Win32.WM_COMMAND, Win32.WINS_ARRANGE_HRZ, 0);
                break;

            case WND_REDRAWN:
                Win32.InvalidateRgn(activeWnd, IntPtr.Zero, true);
                //Win32.GetWindowInfo(ActiveWnd, ref info);
                //x1 = info.rcWindow.left;
                //y1 = info.rcWindow.top;
                //x2 = info.rcWindow.right - x1;
                //y2 = info.rcWindow.bottom - y1;

                //IntPtr screenDc = Win32.GetDC(IntPtr.Zero);
                //IntPtr memDc = Win32.CreateCompatibleDC(screenDc);
                //Win32.SIZE size = new Win32.SIZE(Math.Abs(x2 - x1), Math.Abs(y2 - y1));

                //Win32.POINT pointSource = new Win32.POINT(x1,y1);
                //Win32.POINT topPos = new Win32.POINT(x1, y1);

                //Win32.BLENDFUNCTION blend = new Win32.BLENDFUNCTION();
                //blend.BlendOp = 0;
                //blend.BlendFlags = 0;
                //blend.SourceConstantAlpha = 122;
                //blend.AlphaFormat = 1;

                //Win32.UpdateLayeredWindow(ActiveWnd, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32.ULW_ALPHA);

                ////Win32.InvalidateRect(ActiveWnd, ref info.rcWindow, true);
                ////Win32.MoveWindow(ActiveWnd, x1, y1, x2 - 10, y2 - 10, true);
                ////Win32.UpdateWindow(ActiveWnd);
                ////Win32.SetWindowPos(ActiveWnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_FRAMECHANGED);
                //Win32.ReleaseDC(IntPtr.Zero, screenDc);
                //Win32.DeleteDC(memDc);
                break;
            }
        }