Ejemplo n.º 1
0
        private Screenshot(IntPtr hWnd, bool specialCapturing)
        {
            IsMinimized = NativeMethods.IsIconic(hWnd);
            Handle      = hWnd;
            if (specialCapturing)
            {
                EnterSpecialCapturing(hWnd);
            }
            var wInfo = new Windowinfo
            {
                cbSize = Windowinfo.GetSize()
            };

            NativeMethods.GetWindowInfo(hWnd, ref wInfo);
            var isChild   = false;
            var parent    = NativeMethods.GetParent(hWnd);
            var pos       = new Rectangle();
            var parentPos = new Rectangle();

            if (ForceMdiCapturing && parent != IntPtr.Zero && (wInfo.dwExStyle & ExtendedWindowStyles.WS_EX_MDICHILD) == ExtendedWindowStyles.WS_EX_MDICHILD)
            {
                var name = new StringBuilder();
                NativeMethods.GetClassName(parent, name, RUNDLL.Length + 1);
                if (name.ToString() != RUNDLL)
                {
                    isChild = true;
                    pos     = GetWindowPlacement(hWnd);
                    NativeMethods.MoveWindow(hWnd, int.MaxValue, int.MaxValue, pos.Width, pos.Height, true);

                    NativeMethods.SetParent(hWnd, IntPtr.Zero);

                    parentPos = GetWindowPlacement(parent);
                }
            }
            var rect = GetWindowPlacement(hWnd);

            Size     = rect.Size;
            Location = rect.Location;
            Text     = GetWindowText(hWnd);
            Image    = GetWindowImage(hWnd, Size);
            if (isChild)
            {
                NativeMethods.SetParent(hWnd, parent);
                var x = wInfo.rcWindow.Left - parentPos.X;
                var y = wInfo.rcWindow.Top - parentPos.Y;

                if ((wInfo.dwStyle & WindowStyles.WS_THICKFRAME) == WindowStyles.WS_THICKFRAME)
                {
                    x -= SystemInformation.Border3DSize.Width;
                    y -= SystemInformation.Border3DSize.Height;
                }

                NativeMethods.MoveWindow(hWnd, x, y, pos.Width, pos.Height, true);
            }

            if (specialCapturing)
            {
                ExitSpecialCapturing(hWnd);
            }
        }
Ejemplo n.º 2
0
        private Screenshot(IntPtr hWnd, bool specialCapturing)
        {
            IsMinimized = NativeMethods.IsIconic(hWnd);
            Handle = hWnd;
            if (specialCapturing)
            {
                EnterSpecialCapturing(hWnd);
            }
            var wInfo = new Windowinfo
            {
                cbSize = Windowinfo.GetSize()
            };
            NativeMethods.GetWindowInfo(hWnd, ref wInfo);
            var isChild = false;
            var parent = NativeMethods.GetParent(hWnd);
            var pos = new Rectangle();
            var parentPos = new Rectangle();
            if (ForceMdiCapturing && parent != IntPtr.Zero && (wInfo.dwExStyle & ExtendedWindowStyles.WS_EX_MDICHILD) == ExtendedWindowStyles.WS_EX_MDICHILD)
            {
                var name = new StringBuilder();
                NativeMethods.GetClassName(parent, name, RUNDLL.Length + 1);
                if (name.ToString() != RUNDLL)
                {
                    isChild = true;
                    pos = GetWindowPlacement(hWnd);
                    NativeMethods.MoveWindow(hWnd, int.MaxValue, int.MaxValue, pos.Width, pos.Height, true);

                    NativeMethods.SetParent(hWnd, IntPtr.Zero);

                    parentPos = GetWindowPlacement(parent);
                }
            }
            var rect = GetWindowPlacement(hWnd);
            Size = rect.Size;
            Location = rect.Location;
            Text = GetWindowText(hWnd);
            Image = GetWindowImage(hWnd, Size);
            if (isChild)
            {
                NativeMethods.SetParent(hWnd, parent);
                var x = wInfo.rcWindow.Left - parentPos.X;
                var y = wInfo.rcWindow.Top - parentPos.Y;

                if ((wInfo.dwStyle & WindowStyles.WS_THICKFRAME) == WindowStyles.WS_THICKFRAME)
                {
                    x -= SystemInformation.Border3DSize.Width;
                    y -= SystemInformation.Border3DSize.Height;
                }

                NativeMethods.MoveWindow(hWnd, x, y, pos.Width, pos.Height, true);
            }

            if (specialCapturing)
            {
                ExitSpecialCapturing(hWnd);
            }
        }
Ejemplo n.º 3
0
 public static extern bool GetWindowInfo(IntPtr hwnd, ref Windowinfo pwi);
Ejemplo n.º 4
0
 public static extern bool GetWindowInfo(IntPtr hwnd, ref Windowinfo pwi);