Ejemplo n.º 1
0
 /// <summary>
 /// ウィドウが最小化されている場合、元に戻す
 /// </summary>
 public void Restore()
 {
     if (NativeCall.IsIconic(this.handle))
     {
         NativeCall.ShowWindow(this.handle, NativeCall.WindowShowStyle.Restore);
     }
 }
Ejemplo n.º 2
0
 private void SetWindowMode(IntPtr Mode)
 {
     NativeCall.SetWindowPos(this.handle, Mode, 0, 0, 0, 0,
                             NativeCall.SetWindowPosFlags.SWP_NOACTIVATE |
                             NativeCall.SetWindowPosFlags.SWP_NOMOVE |
                             NativeCall.SetWindowPosFlags.SWP_NOSIZE |
                             NativeCall.SetWindowPosFlags.SWP_NOSENDCHANGING |
                             NativeCall.SetWindowPosFlags.SWP_SHOWWINDOW
                             );
 }
Ejemplo n.º 3
0
        /// <summary>
        /// クライアント領域を画像としてキャプチャする
        /// </summary>
        /// <param name="rectangle">クライアント領域内のキャプチャしたい領域。指定しない場合はクライアント領域全体をキャプチャする。</param>
        /// <returns>キャプチャした画像データ</returns>
        public Bitmap CaptureWindow(Rectangle rectangle = default(Rectangle))
        {
            // ウィンドウが最小化されていた場合、もとに戻す
            // (ウィンドウが最小化されていると座標を取得できないから)
            this.Restore();
            // ウィンドウを最前面に表示する(アクティブにはしない)
            this.SetWindowDispMode("TOP");

            // クライアント領域の左上のスクリーン座標を取得
            NativeCall.POINT screenPoint = new NativeCall.POINT(0, 0);
            NativeCall.ClientToScreen(this.handle, out screenPoint);

            // キャプチャ領域を取得
            NativeCall.RECT clientRect = new NativeCall.RECT();
            NativeCall.GetClientRect(this.handle, out clientRect);
            if (rectangle == default(Rectangle))
            {
                rectangle = new Rectangle(
                    clientRect.left,
                    clientRect.top,
                    clientRect.right - clientRect.left,
                    clientRect.bottom - clientRect.top
                    );
            }
            Point captureStartPoint = new Point(
                screenPoint.X + rectangle.X,
                screenPoint.Y + rectangle.Y
                );
            //Bitmapの作成
            Bitmap bitmap;

            try {
                bitmap = new Bitmap(rectangle.Width, rectangle.Height);
            }
            catch {
                return(null);
            }
            Graphics graphics = Graphics.FromImage(bitmap);

            using (graphics) {
                graphics.CopyFromScreen(captureStartPoint, new Point(0, 0), rectangle.Size);
            }
            return(bitmap);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// クライアント領域をDCを使ってキャプチャする
        /// </summary>
        public Bitmap CaptureWindowDC()
        {
            //アクティブなウィンドウのデバイスコンテキストを取得
            IntPtr winDC = NativeCall.GetWindowDC(handle);

            //ウィンドウの大きさを取得
            NativeCall.RECT winRect = new NativeCall.RECT();
            NativeCall.GetWindowRect(handle, out winRect);
            // クライアント領域の左上のスクリーン座標を取得
            NativeCall.POINT screenPoint = new NativeCall.POINT(0, 0);
            NativeCall.ClientToScreen(this.handle, out screenPoint);
            // クライアント領域を取得
            NativeCall.RECT clientRect = new NativeCall.RECT();
            NativeCall.GetClientRect(this.handle, out clientRect);
            //Bitmapの作成
            Bitmap bmp;

            try {
                bmp = new Bitmap(clientRect.right, clientRect.bottom);
            }
            catch {
                return(null);
            }
            //Graphicsの作成
            Graphics g = Graphics.FromImage(bmp);
            //Graphicsのデバイスコンテキストを取得
            IntPtr hDC = g.GetHdc();

            //Bitmapに画像をコピーする
            NativeCall.BitBlt(hDC, 0, 0, bmp.Width, bmp.Height,
                              winDC, screenPoint.X - winRect.left, screenPoint.Y - winRect.top, SRCCOPY);
            //解放
            g.ReleaseHdc(hDC);
            g.Dispose();
            NativeCall.ReleaseDC(handle, winDC);

            return(bmp);
        }