Exemplo n.º 1
0
        private static Rectangle GetWindowPlacement(IntPtr hWnd)
        {
            WindowRect rect = new WindowRect();

            Win32Ext.GetWindowRect(hWnd, ref rect);
            return(rect);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get Window Name
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        public static string GetWindowName(IntPtr hWnd)
        {
            int           length = Win32Ext.GetWindowTextLength(hWnd) + 1;
            StringBuilder name   = new StringBuilder(length);

            Win32Ext.GetWindowText(hWnd, name, length);
            return(name.ToString());
        }
Exemplo n.º 3
0
 private static bool NeedSpecialCapturing(IntPtr hWnd)
 {
     if (Win32Ext.IsIconic(hWnd))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get Handling Window Coordinate(x,y start point and width,height)
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        public static Rectangle GetWindowCoordinate(IntPtr hWnd)
        {
            WindowInfo wInfo = new WindowInfo()
            {
                cbSize = WindowInfo.GetSize()
            };

            Win32Ext.GetWindowInfo(hWnd, ref wInfo);
            return(wInfo.rcWindow);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get the collection of WindowSnap instances fro all available windows
        /// </summary>
        /// <param name="minimized">Capture a window even it's Minimized</param>
        /// <param name="specialCapturring">use special capturing method to capture minmized windows</param>
        /// <returns>return collections of WindowSnap instances</returns>
        public static WindowSnapCollection GetAllWindows(bool minimized, bool specialCapturring)
        {
            windowSnaps           = new WindowSnapCollection();
            countMinimizedWindows = minimized;         //set minimized flag capture
            useSpecialCapturing   = specialCapturring; //set specialcapturing flag

            Win32Ext.EnumWindowsCallbackHandler callback = new Win32Ext.EnumWindowsCallbackHandler(EnumWindowsCallback);
            Win32Ext.EnumWindows(callback, IntPtr.Zero);

            return(new WindowSnapCollection(windowSnaps.ToArray(), true));
        }
Exemplo n.º 6
0
        private static void ExitSpecialCapturing(IntPtr hWnd)
        {
            Win32Ext.ShowWindow(hWnd, ShowWindowEnum.Minimize);
            Win32Ext.SetWindowLong(hWnd, Win32Ext.GWL_EXSTYLE, winLong);

            if (minAnimateChanged)
            {
                XPAppearance.MinAnimate = true;
                minAnimateChanged       = false;
            }
        }
Exemplo n.º 7
0
        private void EnterSpecialCapturing(IntPtr hWnd)
        {
            if (XPAppearance.MinAnimate)
            {
                XPAppearance.MinAnimate = false;
                minAnimateChanged       = true;
            }

            winLong = Win32Ext.GetWindowLong(hWnd, Win32Ext.GWL_EXSTYLE);
            Win32Ext.SetWindowLong(hWnd, Win32Ext.GWL_EXSTYLE, winLong | Win32Ext.WS_EX_LAYERED);
            Win32Ext.SetLayeredWindowAttributes(hWnd, 0, 1, Win32Ext.LWA_ALPHA);
            Win32Ext.ShowWindow(hWnd, ShowWindowEnum.Restore);
            Win32Ext.SendMessage(hWnd, Win32Ext.WM_PAINT, 0, 0);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get Handling Window Coordinate(x,y start point and width,height)
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        public static Rectangle GetWindowCoordinate(IntPtr hWnd)
        {
            if (hWnd == IntPtr.Zero)
            {
                return(Screen.PrimaryScreen.Bounds);
            }

            WindowInfo wInfo = new WindowInfo()
            {
                cbSize = WindowInfo.GetSize()
            };

            Win32Ext.GetWindowInfo(hWnd, ref wInfo);
            return(wInfo.rcWindow);
        }
Exemplo n.º 9
0
 private static Bitmap GetWindowImage(IntPtr hWnd, Size size)
 {
     try
     {
         if (size.IsEmpty || size.Height < 0 || size.Width < 0)
         {
             return(null);
         }
         Bitmap   bmp = new Bitmap(size.Width, size.Height);
         Graphics g   = Graphics.FromImage(bmp);
         IntPtr   dc  = g.GetHdc();
         Win32Ext.PrintWindow(hWnd, dc, 0);
         g.ReleaseHdc();
         g.Dispose();
         return(bmp);
     }
     catch { return(null); }
 }
Exemplo n.º 10
0
        private WindowSnap(IntPtr hWnd, bool specialCapturing)
        {
            Rectangle rect = GetWindowPlacement(hWnd);

            {
                this.IsMinimized = Win32Ext.IsIconic(hWnd);
                this.Handle      = hWnd;
                this.Size        = rect.Size;
                this.Location    = rect.Location;
                this.Text        = GetWindowText(hWnd);
                this.Image       = GetWindowImage(hWnd, this.Size);
            }

            ChildSupport(hWnd);

            if (specialCapturing)
            {
                EnterSpecialCapturing(hWnd);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Child Window Support
        /// </summary>
        /// <param name="hWnd"></param>
        private void ChildSupport(IntPtr hWnd)
        {
            #region Condition initialize
            WindowInfo wInfo = new WindowInfo()
            {
                cbSize = WindowInfo.GetSize()
            };
            Win32Ext.GetWindowInfo(hWnd, ref wInfo);
            IntPtr parent = Win32Ext.GetParent(hWnd);
            #endregion
            #region Condition
            if (!ForceMDICapturing || parent == IntPtr.Zero ||
                (wInfo.dwExStyle & ExtendedWindowStyles.WS_EX_MDICHILD) != ExtendedWindowStyles.WS_EX_MDICHILD)
            {
                return;
            }

            StringBuilder name = new StringBuilder();
            Win32Ext.GetClassName(parent, name, Win32Ext.RUNDLL.Length + 1);

            if (name.ToString() == Win32Ext.RUNDLL)
            {
                return;
            }
            #endregion
            #region Child Support
            Rectangle pos = GetWindowPlacement(hWnd);
            Win32Ext.MoveWindow(hWnd, int.MaxValue, int.MaxValue, pos.Width, pos.Height, true);
            Win32Ext.SetParent(hWnd, IntPtr.Zero);
            Win32Ext.SetParent(hWnd, parent);
            Rectangle parentPos = GetWindowPlacement(parent);
            int       x         = wInfo.rcWindow.Left - parentPos.X;
            int       y         = wInfo.rcWindow.Top - parentPos.Y;
            if ((wInfo.dwStyle & WindowStyles.WS_THICKFRAME) == WindowStyles.WS_THICKFRAME)
            {
                x -= SystemInformation.Border3DSize.Width;
                y -= SystemInformation.Border3DSize.Height;
            }
            Win32Ext.MoveWindow(hWnd, x, y, pos.Width, pos.Height, true);
            #endregion
        }
Exemplo n.º 12
0
        private static bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
        {
            bool specialCapturing = false;

            if (hWnd == IntPtr.Zero)
            {
                return(false);
            }
            if (!Win32Ext.IsWindowVisible(hWnd))
            {
                return(true);
            }
            if (!countMinimizedWindows)
            {
                if (Win32Ext.IsIconic(hWnd))
                {
                    return(true);
                }
            }
            else if (Win32Ext.IsIconic(hWnd) && useSpecialCapturing)
            {
                specialCapturing = true;
            }

            if (GetWindowText(hWnd) == Win32Ext.PROGRAMMANAGER)
            {
                return(true);
            }

            var Snap = new WindowSnap(hWnd, specialCapturing);

            if (!Snap.Text.Equals(""))
            {
                windowSnaps.Add(Snap);
            }

            return(true);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get Handling Window
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <KeyValuePair <IntPtr, string> > GetHandlingWindowList()
        {
            List <KeyValuePair <IntPtr, string> > list = new List <KeyValuePair <IntPtr, string> >();

            Win32Ext.EnumWindows((hWnd, lParam) =>
            {
                if (hWnd == IntPtr.Zero)
                {
                    return(false);
                }
                if (!Win32Ext.IsWindowVisible(hWnd))
                {
                    return(true);
                }
                string name = GetWindowName(hWnd);
                if (!string.IsNullOrEmpty(name))
                {
                    list.Add(new KeyValuePair <IntPtr, string>(hWnd, name));
                }
                return(true);
            }, IntPtr.Zero);

            return(list);
        }
Exemplo n.º 14
0
 public static IntPtr GetForegroundWindow()
 {
     return(Win32Ext.GetForegroundWindow());
 }
Exemplo n.º 15
0
 public static IntPtr GetTopWindow(IntPtr hWnd)
 {
     return(Win32Ext.GetTopWindow(hWnd));
 }
Exemplo n.º 16
0
 public static bool IsWindowVisible(IntPtr hWnd)
 {
     return(Win32Ext.IsWindowVisible(hWnd));
 }