private System.Drawing.Rectangle GetRecordingCoordinates()
        {
            if (!WindowLocator.GetWindowRect(CaptureWindowPtr, out WindowLocator.RECT rect))
            {
                throw new Exception("Can't find capture window coordinates");
            }

            //not to show recording frame border
            const int ignoredPixels = 3;

            return(new System.Drawing.Rectangle(rect.Left + ignoredPixels, rect.Top + ignoredPixels, rect.Right - rect.Left - ignoredPixels * 2, rect.Bottom - rect.Top - ignoredPixels * 2));
        }
        /// <inheritdoc />
        public MainWindow()
        {
            // to avoid double initialization
            if (_inited)
            {
                return;
            }

            _recorder = new Recorder();
            InitializeComponent();
            ToggleOverlay(true);
            SetResolutionLbl();
            SetCanvasPen();

            WindowLocator.Start();
            WindowLocator.MouseAction += new EventHandler(OnMouseAction);

            _recordingWindow = new RecordingWindow();

            _inited = true;
        }
        private void OnMouseAction(object sender, EventArgs e)
        {
            if (!_isWindowCapturer || !IsVisible || IsRecording || _isCountdown)
            {
                return;
            }

            if (!WindowLocator.GetCursorPos(out WindowLocator.POINT p))
            {
                return;
            }

            IEnumerable <IntPtr> wisibleWindows = WindowLocator.FindWindows();
            IntPtr foundWindow = WindowLocator.WindowFromPoint(p);
            IntPtr window      = wisibleWindows.FirstOrDefault(w => w == foundWindow);

            if (window != null && window != CaptureWindowPtr)
            {
                WindowLocator.SetForegroundWindow(foundWindow);
                WindowLocator.GetWindowRect(foundWindow, out WindowLocator.RECT rect);
                WindowLocator.MoveWindow(CaptureWindowPtr, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, true);
            }
        }
Ejemplo n.º 4
0
        private void CaptureFrame(object sender, NewFrameEventArgs eventArgs)
        {
            lock (_syncObj)
            {
                if (!_isRecording)
                {
                    return;
                }

                using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                {
                    using (Graphics graphics = Graphics.FromImage(bitmap))
                    {
                        WindowLocator.CURSORINFO pci;
                        pci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(WindowLocator.CURSORINFO));

                        if (WindowLocator.GetCursorInfo(out pci))
                        {
                            if (pci.flags == WindowLocator.CURSOR_SHOWING)
                            {
                                var cursorX = pci.ptScreenPos.X - _position.Left;
                                var cursorY = pci.ptScreenPos.Y - _position.Top;

                                WindowLocator.DrawIcon(graphics.GetHdc(), cursorX, cursorY, pci.hCursor);
                                graphics.ReleaseHdc();

                                DrawCursorHighlight(graphics, cursorX, cursorY);
                            }
                        }

                        DrawWatermark(graphics, bitmap.Width, bitmap.Height);
                    }

                    _videoWriter.WriteVideoFrame(bitmap);
                }
            }
        }