示例#1
0
        //private IEnumerable<IntPtr> GetWindowHandles(IntPtr handle, int indent)
        //{
        //    yield return handle;
        //    var childHandles = new ChildWindowHandles(handle);
        //    if(!childHandles.Any())
        //    {
        //        yield break;
        //    }
        //    foreach (var childHandle in childHandles)
        //    {
        //        yield return childHandle;
        //    }
        //}

        /// <summary>
        /// 指定した対象を指定した種類でキャプチャする
        /// </summary>
        /// <param name="target">キャプチャ対象</param>
        /// <param name="type">キャプチャ種類</param>
        private void CaptureImage(CaptureTarget target, CaptureType type)
        {
            //List<WindowInfo> windowInfos = new List<WindowInfo>();
            //foreach (var handle in new TopLevelWindowHandles())
            //{
            //    windowInfos.Add(new WindowInfo(handle));
            //}

            //foreach(var windowInfo in windowInfos)
            //{
            //    Console.WriteLine($"{windowInfo.WindowText} : {windowInfo.ClassName}");
            //}

            try
            {
                // キーボードフック中断
                KeyboardHook.Pause();

                // 矩形領域
                if (target == CaptureTarget.RectArea)
                {
                    using (Bitmap screenBitmap = this.CaptureScreen())
                        using (CaptureForm captureForm = new CaptureForm(screenBitmap))
                        {
                            captureForm.ShowDialog();
                            using (Bitmap captureBitmap = captureForm.CaptureBitmap)
                            {
                                this.SaveImage(captureBitmap, type);
                            }
                        }
                }
                // デスクトップ
                else if (target == CaptureTarget.Desktop)
                {
                    using (Bitmap captureBitmap = this.CaptureScreen())
                    {
                        this.SaveImage(captureBitmap, type);
                    }
                }
                // アクティブウィンドウ
                else if (target == CaptureTarget.ActiveWindow)
                {
                    using (Bitmap captureBitmap = this.CaptureActiveWindow())
                    {
                        this.SaveImage(captureBitmap, type);
                    }
                }
            }
            finally
            {
                // キーボードフック再開
                KeyboardHook.Start();
            }
        }
示例#2
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="screenBitmap">矩形選択対象のビットマップ</param>
 /// <param name="mousePoiont">マウスカーソルの初期位置</param>
 public CoordinateForm(CaptureForm captureForm, Bitmap screenBitmap, Point mousePoiont)
 {
     // コンポーネントの初期化
     InitializeComponent();
     // マウスイベントハンドラの初期化
     this.InitializeMouseEventHandler(this);
     // 親フォーム
     this.captureForm = captureForm;
     // 矩形選択対象のBitmap
     this.screenBitmap = screenBitmap;
     // マウス位置
     this.mousePoint = mousePoiont;
 }