Example #1
0
        private Tree CaptureWindow(IntPtr hwnd, Win32.WINDOWINFO windowinfo, bool usePrintWindow, bool fixedSize = false)
        {
            BoundingBox windowRect = new BoundingBox(windowinfo.rcWindow.left, windowinfo.rcWindow.top,
                            windowinfo.rcWindow.right - windowinfo.rcWindow.left + 1, windowinfo.rcWindow.bottom - windowinfo.rcWindow.top + 1);

            var attributes = GetWindowAttributes(hwnd, windowinfo);

            if (windowRect.Width > 0 && windowRect.Height > 0)
            {
                System.Drawing.Bitmap bmp;
                int width = windowRect.Width;
                int height = windowRect.Height;

                if(fixedSize)
                {
                    width = (int)System.Windows.SystemParameters.VirtualScreenWidth;
                    height = (int)System.Windows.SystemParameters.VirtualScreenHeight;
                }

                if (!usePrintWindow)
                    bmp = GetBitmapFromScreen(hwnd, null, width, height);
                else
                    bmp = GetBitmapFromPrintWindow(hwnd, null, width, height);

                Tree window = _bitmapToTree.GetScreenshotAndCreateTree(windowRect.Width, windowRect.Height, bmp, attributes);
                //_pool.ReturnInstance(bmp);
                return window;
            }

            return null;
        }
Example #2
0
        /// <summary>
        /// Get state according to fullscreen option
        /// </summary>
        /// <param name="wndHandle"></param>
        /// <returns></returns>
        public bool GetFullScreenState(bool currentState, IntPtr wndHandle)
        {
            bool enabled = currentState;

            System.Drawing.Rectangle screen = System.Windows.Forms.Screen.FromHandle(wndHandle).Bounds;
            Win32.RECT screenSize           = new Win32.RECT(screen);

            Win32.WINDOWINFO info = new Win32.WINDOWINFO();
            Win32.GetWindowInfo(wndHandle, ref info);
            //Debug.WriteLine(string.Format("Wnd left: {0}, top: {1}, right: {2}, bottom: {3}",
            //    info.rcWindow.left, info.rcWindow.top, info.rcWindow.right, info.rcWindow.bottom));
            if (info.rcWindow.Equals(screenSize))
            {
                switch (Config.User.StateFullScreen)
                {
                case 1: enabled = true; break;

                case 2: enabled = false; break;
                }
            }
            else
            {
                switch (Config.User.StateFullScreen)
                {
                case 1: enabled = false; break;

                case 2: enabled = true; break;
                }
            }
            return(enabled);
        }
Example #3
0
        /// <summary>
        /// Currently determines the closest window to the cursor.
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="lparams"></param>
        /// <returns></returns>
        private bool EnumWindows(IntPtr hwnd, IntPtr lparams)
        {
            Win32.WINDOWINFO windowinfo = new Win32.WINDOWINFO(true);
            Win32.GetWindowInfo(hwnd, ref windowinfo);
            Tree occurrence = CaptureWindowWithoutPixels(hwnd, windowinfo);

            _windows.Add(occurrence);

            return true;
        }
Example #4
0
        private static void SetWindowFromInfo(IntPtr hwnd, Win32.WINDOWINFO info)
        {
            int x1 = info.rcWindow.left;
            int y1 = info.rcWindow.top;
            int x2 = info.rcWindow.right - x1;
            int y2 = info.rcWindow.bottom - y1;

            //Win32.SetWindowLong(hwnd, Win32.GWL_STYLE, (int)info.dwStyle);
            //Win32.SetWindowLong(hwnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle);
            Win32.SetWindowPos(hwnd, Win32.HWND_NOTOPMOST, x1, y1, x2, y2, Win32.SWP_SHOWWINDOW);
        }
Example #5
0
        private Tree CaptureWindowWithoutPixels(IntPtr hwnd, Win32.WINDOWINFO windowinfo)
        {
            BoundingBox windowRect = new BoundingBox(windowinfo.rcWindow.left, windowinfo.rcWindow.top,
              windowinfo.rcWindow.right - windowinfo.rcWindow.left + 1, windowinfo.rcWindow.bottom - windowinfo.rcWindow.top + 1);

            Dictionary<string, object> attributes = GetWindowAttributes(hwnd, windowinfo);

            if (windowRect.Width > 0 && windowRect.Height > 0)
            {

                Tree window = Tree.FromBoundingBox(windowRect, attributes);
                return window;
            }

            return null;
        }
Example #6
0
 public static void SetWindowTrasparency(IntPtr hWnd, int visibility)
 {
     if (visibility == 100)
     {
         Win32.WINDOWINFO info = new Win32.WINDOWINFO();
         Win32.GetWindowInfo(hWnd, ref info);
         Win32.SetWindowLong(hWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_LAYERED);
     }
     else
     {
         int num = Win32.GetWindowLong(hWnd, Win32.GWL_EXSTYLE);
         num |= Win32.WS_EX_LAYERED;
         Win32.SetWindowLong(hWnd, Win32.GWL_EXSTYLE, num);
         Win32.SetLayeredWindowAttributes(hWnd, 0, (byte)Math.Round((double)((((double)visibility) / 100) * 255)), Win32.LWA_ALPHA);
     }
 }
Example #7
0
        private void ThreadRun(object arg)
        {
            if (!_running)
            {
                _running = true;

                while (!_exitEvent.WaitOne(0, false))
                {
                    IntPtr windowHandle = (IntPtr)arg;
                    //Get the active window so we can translate it.
                    Tree window = _windowCapture.CaptureWindowWithPixels(windowHandle, UsePrintWindow, false);

                    if (window != null)
                    {
                        Prefab.Bitmap         capture = window["capturedpixels"] as Prefab.Bitmap;
                        System.Drawing.Bitmap bmp     = _pool.GetInstance(capture.Width, capture.Height);
                        Bitmap.ToSystemDrawingBitmap(capture, bmp);

                        // Get Window features
                        Win32.WINDOWINFO windowinfo = new Win32.WINDOWINFO(true);
                        Win32.GetWindowInfo(windowHandle, ref windowinfo);

                        // Save as png image
                        String filename = string.Format("{0}_f{1:D4}.png", _saveLoc.Substring(0, _saveLoc.Length - 4), frame_num);
                        bmp.Save(@filename, ImageFormat.Png);
                        frame_num++;


                        if (_videoStream == null)
                        {
                            _videoStream = _aviManager.AddVideoStream(false, 20, bmp);
                        }
                        else
                        {
                            _videoStream.AddFrame(bmp);
                        }

                        _pool.ReturnInstance(bmp);
                    }

                    //Let's not melt our processor ;)
                    Thread.Sleep(50);
                }
                _running = false;
                _aviManager.Close();
            }
        }
Example #8
0
        public bool CheckForWindow()
        {
            if ((GrabWidth == 0) || (GrabHeight == 0))
            {
                Win32.WINDOWINFO window = new Win32.WINDOWINFO();
                Win32.POINT      pt     = new Win32.POINT(GrabX, GrabY);
                IntPtr           hwnd   = Win32.WindowFromPoint(pt);
                do
                {
                    Win32.GetWindowInfo(hwnd, ref window);
                    if ((window.dwStyle & Win32.WS_CAPTION) == 0)
                    {
                        hwnd = Win32.GetParent(hwnd);
                    }
                } while ((hwnd != IntPtr.Zero) && (window.dwStyle & Win32.WS_CAPTION) == 0);
                if (hwnd == IntPtr.Zero)
                {
                    return(false);
                }

                Win32.SetForegroundWindow(hwnd);
                Thread.Sleep(1000);

                xBegin  = window.rcWindow.left;
                xCursor = window.rcWindow.right;
                yBegin  = window.rcWindow.top;
                yCursor = window.rcWindow.bottom;

                // bug #49
                int borderX = SystemInformation.FixedFrameBorderSize.Width + 2;
                int borderY = SystemInformation.FixedFrameBorderSize.Height + 2;
                if (((window.dwExStyle & Win32.WS_EX_DLGMODALFRAME) == Win32.WS_EX_DLGMODALFRAME) ||
                    ((window.dwExStyle & Win32.WS_EX_TOOLWINDOW) == Win32.WS_EX_TOOLWINDOW) ||
                    ((window.dwExStyle & Win32.WS_EX_PALETTEWINDOW) == Win32.WS_EX_PALETTEWINDOW))
                {
                    xBegin   = Math.Max(0, xBegin - borderX);
                    xCursor += borderX;
                    yBegin   = Math.Max(0, yBegin - borderY);
                    yCursor += borderY;
                }
            }

            return(true);
        }
Example #9
0
        private Dictionary<string, object> GetWindowAttributes(IntPtr hwnd, Win32.WINDOWINFO windowinfo)
        {
            Dictionary<string, object> attributes = new Dictionary<string, object>();
            attributes["handle"] = hwnd;

            ExpensiveWindowInfo expensiveInfo;

            if (!_windowInfo.TryGetValue(hwnd, out expensiveInfo))
            {
                expensiveInfo = new ExpensiveWindowInfo(Win32.GetClassName(hwnd), Win32.GetWindowText(hwnd), Win32.GetProcessPathFromWindowHandle(hwnd));
                _windowInfo.Add(hwnd, expensiveInfo);
            }

            attributes["processfilename"] = expensiveInfo.ProcessFilePath;
            attributes["title"] = expensiveInfo.Title;
            attributes["classname"] = expensiveInfo.ClassName;
            attributes["style"] = windowinfo.dwStyle;
            attributes["exstyle"] = windowinfo.dwExStyle;

            return attributes;
        }
Example #10
0
        /// <summary>
        /// Get state according to fullscreen option
        /// </summary>
        /// <param name="wndHandle"></param>
        /// <returns></returns>
        public bool GetFullScreenState(bool currentState, IntPtr wndHandle)
        {
            bool enabled = currentState;

            System.Drawing.Rectangle screen = System.Windows.Forms.Screen.FromHandle(wndHandle).Bounds;
            Win32.RECT screenSize = new Win32.RECT(screen);

            Win32.WINDOWINFO info = new Win32.WINDOWINFO();
            Win32.GetWindowInfo(wndHandle, ref info);
            //Debug.WriteLine(string.Format("Wnd left: {0}, top: {1}, right: {2}, bottom: {3}",
            //    info.rcWindow.left, info.rcWindow.top, info.rcWindow.right, info.rcWindow.bottom));
            if (info.rcWindow.Equals(screenSize))
            {
                switch (Config.User.StateFullScreen)
                {
                    case 1: enabled = true; break;
                    case 2: enabled = false; break;
                }
            }
            else
            {
                switch (Config.User.StateFullScreen)
                {
                    case 1: enabled = false; break;
                    case 2: enabled = true; break;
                }
            }
            return enabled;
        }
        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;
            }
        }
 public static void SetWindowTrasparency(IntPtr hWnd, int visibility)
 {
     if (visibility == 100)
     {
         Win32.WINDOWINFO info = new Win32.WINDOWINFO();
         Win32.GetWindowInfo(hWnd, ref info);
         Win32.SetWindowLong(hWnd, Win32.GWL_EXSTYLE, (int)info.dwExStyle & ~Win32.WS_EX_LAYERED);
     }
     else
     {
         int num = Win32.GetWindowLong(hWnd, Win32.GWL_EXSTYLE);
         num |= Win32.WS_EX_LAYERED;
         Win32.SetWindowLong(hWnd, Win32.GWL_EXSTYLE, num);
         Win32.SetLayeredWindowAttributes(hWnd, 0, (byte)Math.Round((double)((((double)visibility) / 100) * 255)), Win32.LWA_ALPHA);
     }
 }
Example #13
0
 public Tree CaptureWindowWithPixels(IntPtr hwnd, bool usePrintWindow, bool fixedSize = false)
 {
     Win32.WINDOWINFO windowinfo = new Win32.WINDOWINFO(true);
     Win32.GetWindowInfo(hwnd, ref windowinfo);
     return CaptureWindow(hwnd, windowinfo, usePrintWindow, fixedSize);
 }
Example #14
0
 public Tree CaptureWindowWithoutPixels(IntPtr hwnd)
 {
     Win32.WINDOWINFO windowinfo = new Win32.WINDOWINFO(true);
     Win32.GetWindowInfo(hwnd, ref windowinfo);
     return CaptureWindowWithoutPixels(hwnd, windowinfo);
 }
Example #15
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;
            }
        }