예제 #1
0
        public void CleanUp()
        {
            if (_clipState)
            {
                User32.ClipCursor(ref _defaultCursorBounds);
                _clipState = false;
            }

            User32.UnhookWinEvent(m_hhook);
        }
예제 #2
0
        public void ProcessService()
        {
            if (CurrentWindowHandle == null ||
                CurrentExecutable == null)
            {
                return;
            }

            if (_altTabWindowHandle == CurrentWindowHandle)
            {
                return;
            }

            switch (Mode)
            {
            case ServiceMode.NormalMode:
                DoNormalMode();
                break;

            case ServiceMode.CaptureMode:
                DoCaptureMode();
                break;
            }

            //set lock if needed ...
            if (_lockState)
            {
                //backup current cursor bounds first ...
                if (!_clipState)
                {
                    User32.GetClipCursor(out _defaultCursorBounds);
                }

                //set new cursor bounds ...
                User32.ClipCursor(ref _currentWindowBounds);
                _clipState = true;
            }
            else if (_clipState)
            {
                //restore default cursor bounds ...
                User32.ClipCursor(ref _defaultCursorBounds);
                _clipState = false;
            }
        }
예제 #3
0
        /// <inheritdoc />
        public void Initialize(ref GameGraphicsParameters parameters)
        {
            if (_isInitialized)
            {
                return;
            }

            _renderForm.WindowState = parameters.DisplayType == DisplayType.FullscreenWindow
                ? RenderForm.FormWindowState.Maximized
                : RenderForm.FormWindowState.Normal;

            _renderForm.BorderStyle = parameters.DisplayType == DisplayType.Window
                ? RenderForm.FormBorderStyle.Fixed
                : RenderForm.FormBorderStyle.None;

            parameters.Handle = _renderForm.CreateWindow(parameters.Width, parameters.Height);

            if (parameters.DisplayType == DisplayType.FullscreenWindow)
            {
                User32.GetClientRect(parameters.Handle, out RECT rcRect);
                parameters.Width  = rcRect.RightBottom.X;
                parameters.Height = rcRect.RightBottom.Y;
            }

            bool isMouseVisible = parameters.IsMouseVisible;
            bool clipCursor     = parameters.ClipCursor;

            _renderForm.MouseEnter += hWnd =>
            {
                if (!isMouseVisible)
                {
                    User32.ShowCursor(false);
                }
                if (clipCursor)
                {
                    RECT rect = new RECT(Width, Height);
                    if (User32.ClientToScreen(hWnd, ref rect.LeftTop) &&
                        User32.ClientToScreen(hWnd, ref rect.RightBottom))
                    {
                        User32.ClipCursor(ref rect);
                    }
                }
            };

            _renderForm.MouseLeave += hWnd =>
            {
                if (!isMouseVisible)
                {
                    User32.ShowCursor(true);
                }
            };

            if (clipCursor)
            {
                RECT rect = new RECT(Width, Height);
                if (User32.ClientToScreen(parameters.Handle, ref rect.LeftTop) &&
                    User32.ClientToScreen(parameters.Handle, ref rect.RightBottom))
                {
                    User32.ClipCursor(ref rect);
                }
            }

            _isInitialized = true;
        }