Esempio n. 1
0
 public void UnsetWindow()
 {
     if (IsRegistered)
     {
         DesktopWindowManager.Unregister(thumbnail);
         thumbnail = IntPtr.Zero;
     }
     target = null;
 }
Esempio n. 2
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. 3
0
        public void BringToFront()
        {
            Window owner = Window.GetWindow(this);

            if (IsRegistered && owner != null)
            {
                DesktopWindowManager.Unregister(thumbnail);
                thumbnail = DesktopWindowManager.Register(owner, target);
                UpdateThumbnail();
            }
        }
Esempio n. 4
0
        private void AddDwmMenu(ItemsControl items)
        {
            ContextMenu.Items.Add(new Separator());
            MenuItem compositionItem = new MenuItem()
            {
                Header      = "デスクトップ コンポジションを無効にする",
                IsCheckable = true,
                IsChecked   = !DesktopWindowManager.IsCompositionEnabled,
            };

            compositionItem.Click += (sender, e) => DesktopWindowManager.EnableComposition(!compositionItem.IsChecked);
            ContextMenu.Items.Add(compositionItem);
        }
Esempio n. 5
0
        private void windowObserver_DoWork(object sender, DoWorkEventArgs e)
        {
            Size sourceSize = DesktopWindowManager.QueryThumbnailSourceSize(thumbnail);

            while (ApplicationWindow.GetApplicationWindows().Any(window => window.Handle == windowHandle))
            {
                Size size = DesktopWindowManager.QueryThumbnailSourceSize(thumbnail);
                if (!sourceSize.Equals(size))
                {
                    sourceSize = size;
                    OnSourceSizeChanged(EventArgs.Empty);
                }
            }
        }
Esempio n. 6
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. 7
0
        public void UnsetWindow()
        {
            windowHandle = IntPtr.Zero;
            if (windowObserver.IsBusy)
            {
                windowObserver.CancelAsync();
            }
            if (thumbnail != IntPtr.Zero)
            {
                DesktopWindowManager.Unregister(thumbnail);
                thumbnail = IntPtr.Zero;
            }

            OnSourceWindowChanged(EventArgs.Empty);
        }
Esempio n. 8
0
        public WindowCaptureForm()
        {
            InitializeComponent();

            notifyIcon.Icon         = this.Icon;
            notifyIcon.Visible      = true;
            NoSelectionItem         = new ToolStripMenuItem("ウィンドウが見つかりません");
            NoSelectionItem.Enabled = false;
            addWindowsToolStripMenuItem.DropDownItems.Add(NoSelectionItem);

#if DEBUG
            ToolStripMenuItem dwmCompositionEnabledItem = new ToolStripMenuItem("DMW コンポジションを無効にする");
            dwmCompositionEnabledItem.CheckOnClick    = true;
            dwmCompositionEnabledItem.CheckedChanged += (sender, e) => DesktopWindowManager.DwmEnableComposition(!dwmCompositionEnabledItem.Checked);
            ContextMenuStrip.Items.Add(new ToolStripSeparator());
            ContextMenuStrip.Items.Add(dwmCompositionEnabledItem);
#endif
        }
Esempio n. 9
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();
                }
            }
        }
Esempio n. 10
0
        private void UpdateThumbnail(Point location, Size size)
        {
            DWM_THUMBNAIL_PROPERTIES properties = new DWM_THUMBNAIL_PROPERTIES()
            {
                dwFlags = DWM_TNP.DWM_TNP_OPACITY | DWM_TNP.DWM_TNP_RECTDESTINATION | DWM_TNP.DWM_TNP_RECTSOURCE | DWM_TNP.DWM_TNP_SOURCECLIENTAREAONLY | DWM_TNP.DWM_TNP_VISIBLE,
                fSourceClientAreaOnly = ClientAreaOnly,
                fVisible      = true,
                opacity       = (byte)(Byte.MaxValue * Opacity),
                rcDestination = new RECT(location.X, location.Y, size.Width, size.Height),
                rcSource      = new RECT(DrawnRegion),
            };

            if (DesktopWindowManager.Update(thumbnail, ref properties))
            {
                OnThumbnailUpdated(this, EventArgs.Empty);
            }
            else
            {
                OnThumbnailUpdateFailed(this, EventArgs.Empty);
            }
        }
Esempio n. 11
0
 private void UpdateThubmnail()
 {
     if (thumbnail != IntPtr.Zero)
     {
         DWM_THUMBNAIL_PROPERTIES properties = new DWM_THUMBNAIL_PROPERTIES()
         {
             dwFlags = DWM_TNP.DWM_TNP_OPACITY | DWM_TNP.DWM_TNP_RECTDESTINATION | DWM_TNP.DWM_TNP_RECTSOURCE | DWM_TNP.DWM_TNP_SOURCECLIENTAREAONLY | DWM_TNP.DWM_TNP_VISIBLE,
             fSourceClientAreaOnly = ClientAreaOnly,
             fVisible      = Visible & !IsFixed,
             opacity       = Byte.MaxValue,
             rcDestination = new RECT(Location, Size),
             rcSource      = new RECT(DrawnRegion)
         };
         if (!DesktopWindowManager.Update(thumbnail, ref properties))
         {
             if (MessageBox.Show("サムネイルの更新に失敗しました。", "エラー", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) != DialogResult.Retry)
             {
                 UnsetWindow();
             }
         }
     }
 }