Esempio n. 1
0
        //public Image CaptureCurrentImage()
        //{
        //   RECT rect;
        //   GetWindowRect(windowHandle, out rect);
        //   Size size = rect.Size;

        //   if (size.IsEmpty)
        //   {
        //      throw new ApplicationException("ウィンドウサイズが取得できませんでした。");
        //   }

        //   // ウィンドウ枠も含めてウィンドウ全体をビットマップに描画する。
        //   IntPtr deviceContext = GetWindowDC(windowHandle);
        //   Bitmap bitmap = new Bitmap(size.Width, size.Height);
        //   using (Graphics g = Graphics.FromImage(bitmap))
        //   {
        //      IntPtr hDC = g.GetHdc();
        //      BitBlt(hDC, 0, 0, bitmap.Width, bitmap.Height, deviceContext, 0, 0, SRCCOPY);
        //      g.ReleaseHdc(hDC);
        //   }
        //   ReleaseDC(windowHandle, deviceContext);

        //   Padding borderMargin = new Padding();
        //   if (ClientAreaOnly)
        //   {
        //      RECT clientRect;
        //      GetClientRect(windowHandle, out clientRect);
        //      Size clientSize = clientRect.Size;
        //      int borderWidth = (size.Width - clientSize.Width) / 2;
        //      borderMargin.Left = borderWidth;
        //      borderMargin.Right = borderWidth;
        //      borderMargin.Bottom = borderWidth;
        //      borderMargin.Top = size.Height - clientSize.Height - borderWidth;
        //   }

        //   Bitmap clippedBitmap = new Bitmap(DrawnSize.Width, DrawnSize.Height);
        //   using (Graphics g = Graphics.FromImage(clippedBitmap))
        //   {
        //      Rectangle clippedRegion = new Rectangle(
        //         drawnRegion.Left + borderMargin.Left,
        //         drawnRegion.Top + borderMargin.Top,
        //         drawnRegion.Width,
        //         drawnRegion.Height
        //      );
        //      g.InterpolationMode = InterpolationMode.Bicubic;
        //      g.DrawImage(bitmap, new Rectangle(Point.Empty, clippedBitmap.Size), clippedRegion, GraphicsUnit.Pixel);
        //   }

        //   bitmap.Dispose();
        //   return clippedBitmap;
        //}

        //private const int SRCCOPY = 0x00CC0020;

        //[DllImport("user32.dll")]
        //private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
        //[DllImport("user32.dll")]
        //private static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
        //[DllImport("user32.dll")]
        //private static extern IntPtr GetWindowDC(IntPtr hWnd);
        //[DllImport("user32.dll")]
        //private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
        //[DllImport("gdi32.dll")]
        //private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

        public new void BringToFront()
        {
            base.BringToFront();
            if (thumbnail != IntPtr.Zero)
            {
                DesktopWindowManager.Unregister(thumbnail);
                thumbnail = IntPtr.Zero;
            }
            thumbnail = DesktopWindowManager.Register(FindForm(), windowHandle);
            UpdateThubmnail();
        }
Esempio n. 2
0
        public void BringToFront()
        {
            Window owner = Window.GetWindow(this);

            if (IsRegistered && owner != null)
            {
                DesktopWindowManager.Unregister(thumbnail);
                thumbnail = DesktopWindowManager.Register(owner, target);
                UpdateThumbnail();
            }
        }
Esempio n. 3
0
        public void SetWindow(IntPtr windowHandle)
        {
            UnsetWindow();

            if (windowHandle != IntPtr.Zero && DesktopWindowManager.IsCompositionEnabled)
            {
                this.windowHandle = windowHandle;

                thumbnail = DesktopWindowManager.Register(FindForm(), windowHandle);
                windowObserver.RunWorkerAsync();

                OnSourceWindowChanged(EventArgs.Empty);
            }
        }
Esempio n. 4
0
        public void SetWindow(ApplicationWindow window)
        {
            if (Window.GetWindow(this) == null)
            {
                throw new InvalidOperationException();
            }

            if (window != null && DesktopWindowManager.IsCompositionEnabled)
            {
                target = window;
                Window owner = Window.GetWindow(this);
                if (owner != null)
                {
                    thumbnail = DesktopWindowManager.Register(owner, target);
                    ResetDrawnRegion();
                    UpdateThumbnail();
                }
            }
        }