示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            ScreenCaptureAreaOptions captureAreaOptions = ScreenCaptureEngine.DefaultCaptureAreaOptions;

            captureAreaOptions.AreaType = ScreenCaptureAreaType.Rectangle;
            captureAreaOptions.Flags    = ScreenCaptureAreaFlags.ShowDrawCursor;
            // hide our window
            this.SendToBack();
            // Start the capturing (snipping) operation
            try
            {
                scEngine.CaptureArea(captureAreaOptions, null);
            }
            catch (Exception)
            {
                // If something goes wrong or the user hits ESC, don't try to OCR
                return;
            }
            finally
            {
                // Show our window whether the user captured or not.
                this.BringToFront();
            }
        }
示例#2
0
        private void DoCapture(CaptureType captureType)
        {
            if (_isHotKeyEnabled)
            {
                if (_captureType == captureType)
                {
                    return;
                }
            }

            _captureType = captureType;
            _engine.StopCapture();
            UpdateMyControls();
            UpdateStatusBarText();

            string hotkeyMsg = string.Format(DemosGlobalization.GetResxString(GetType(), "Resx_ActiveCapture"), _options.Hotkey.ToString());

            MessageBox.Show(hotkeyMsg);

            if (_minimizeOnCapture)
            {
                _previousWindowState = this.WindowState;
                this.WindowState     = FormWindowState.Minimized;
            }

            try
            {
                switch (captureType)
                {
                case CaptureType.ActiveWindow:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureActiveWindow(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        else
                        {
                            _isHotKeyEnabled = false;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.ActiveWindow) && (_isHotKeyEnabled));
                    break;

                case CaptureType.ActiveClient:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureActiveClient(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.ActiveClient) && (_isHotKeyEnabled));
                    break;

                case CaptureType.FullScreen:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureFullScreen(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.FullScreen) && (_isHotKeyEnabled));
                    break;

                case CaptureType.SelectedObject:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureSelectedObject(_objectOptions, _captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.SelectedObject) && (_isHotKeyEnabled));
                    break;

                case CaptureType.MenuUnderCursor:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureMenuUnderCursor(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.MenuUnderCursor) && (_isHotKeyEnabled));
                    break;

                case CaptureType.Area:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureArea(_areaOptions, _captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.Area) && (_isHotKeyEnabled));
                    break;

                case CaptureType.WallPaper:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureWallpaper(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.WallPaper) && (_isHotKeyEnabled));
                    break;

                case CaptureType.MouseCursor:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureMouseCursor(Color.Yellow, _captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.MouseCursor) && (_isHotKeyEnabled));
                    break;

                case CaptureType.WindowUnderCursor:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureWindowUnderCursor(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateMyControls();
                    } while ((_captureType == CaptureType.WindowUnderCursor) && (_isHotKeyEnabled));
                    break;
                }
            }
            catch (Exception ex)
            {
                if (ex.Message != "NoImage" && ex.Message != "UserAbort" && ex.Message != "Invalid image" &&
                    ex.Message != "User has aborted operation" && ex.Message != "No menu")
                {
                    Messager.ShowError(this, ex);
                }

                _captureType = CaptureType.None;
                UpdateMyControls();
                UpdateStatusBarText();

                if (_minimizeOnCapture)
                {
                    this.WindowState = _previousWindowState;
                }
            }
        }
示例#3
0
        private void DoCapture(CaptureType captureType)
        {
            if (_isHotKeyEnabled)
            {
                if (_captureType == captureType)
                {
                    UpdateScreenCaptureItems();
                    return;
                }
            }

            _mySettings._settings.capturetype = captureType;
            _mySettings.Save();
            UpdateToolBarState();
            _captureType = captureType;
            UpdateScreenCaptureItems();
            _engine.StopCapture();
            try
            {
                switch (captureType)
                {
                case CaptureType.ActiveWindow:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureActiveWindow(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        else
                        {
                            _isHotKeyEnabled = false;
                        }
                        UpdateScreenCaptureItems();
                    } while ((_captureType == CaptureType.ActiveWindow) && (_isHotKeyEnabled));
                    break;

                case CaptureType.FullScreen:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureFullScreen(_captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateScreenCaptureItems();
                    } while ((_captureType == CaptureType.FullScreen) && (_isHotKeyEnabled));
                    break;

                case CaptureType.SelectedObject:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureSelectedObject(_objectOptions, _captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateScreenCaptureItems();
                    } while ((_captureType == CaptureType.SelectedObject) && (_isHotKeyEnabled));
                    break;

                case CaptureType.Area:
                    do
                    {
                        RasterImage image = null;
                        try
                        {
                            image = _engine.CaptureArea(_areaOptions, _captureInformation);
                        }
                        catch (RasterException ex)
                        {
                            if (ex.Message == "UserAbort" || ex.Message == "User has aborted operation")
                            {
                                _captureType = CaptureType.None;
                            }
                        }
                        if (image == null)
                        {
                            _captureType = CaptureType.None;
                        }
                        UpdateScreenCaptureItems();
                    } while ((_captureType == CaptureType.Area) && (_isHotKeyEnabled));
                    break;
                }
            }
            catch (Exception ex)
            {
                bool bTopMost = logWindow.TopMost;
                logWindow.TopMost = false;
                if (ex.Message != "NoImage" && ex.Message != "UserAbort" && ex.Message != "Invalid image" &&
                    ex.Message != "User has aborted operation" && ex.Message != "No menu")
                {
                    Messager.ShowError(this, ex);
                }
                logWindow.TopMost = bTopMost;
                _captureType      = CaptureType.None;
                UpdateScreenCaptureItems();
            }
        }