Ejemplo n.º 1
0
        public EngineWindow(string name, string icon, Size size)
        {
            Name = name; Icon = icon;
            Size = size;

            mWndProc = WindowProc;

            LogEmitter.Apply(LogLevel.Information, "[Start Create Window] [Name = {0}] from [EngineWindow]", Name);

            //get instance
            var hInstance = APILibrary.Win32.Internal.GetModuleHandle(null);

            //create app info(WNDCLASS)s, default setting
            var appInfo = new APILibrary.Win32.AppInfo()
            {
                style         = (uint)APILibrary.Win32.AppInfoStyle.CS_DBLCLKS,
                lpfnWndProc   = mWndProc,
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = hInstance,
                hIcon         = APILibrary.Win32.Internal.LoadImage(IntPtr.Zero, Icon, 1, 0, 0, 0x00000010),
                hbrBackground = APILibrary.Win32.Internal.GetStockObject(0),
                hCursor       = APILibrary.Win32.Internal.LoadCursor(IntPtr.Zero, (uint)APILibrary.Win32.CursorType.IDC_ARROW),
                lpszMenuName  = null,
                lpszClassName = Name
            };

            //register app info(WNDCLASS)
            APILibrary.Win32.Internal.RegisterAppinfo(ref appInfo);

            APILibrary.Win32.Rect rect = new APILibrary.Win32.Rect()
            {
                top = 0, left = 0, right = Size.Width, bottom = Size.Height
            };

            //get real rect
            APILibrary.Win32.Internal.AdjustWindowRect(ref rect, (uint)APILibrary.Win32.WindowStyles.WS_OVERLAPPEDWINDOW, false);

            //create window
            mHandle = APILibrary.Win32.Internal.CreateWindowEx(0, Name, Name,
                                                               (uint)APILibrary.Win32.WindowStyles.WS_OVERLAPPEDWINDOW, 0x80000000, 0x80000000,
                                                               rect.right - rect.left, rect.bottom - rect.top, IntPtr.Zero, IntPtr.Zero,
                                                               hInstance, IntPtr.Zero);

            LogEmitter.Apply(LogLevel.Information, "[Finish Create Window] [Width = {0}] [Height = {1}] from [EngineWindow]",
                             Size.Width, Size.Height);

            //get window rect property
            APILibrary.Win32.Internal.GetWindowRect(mHandle, ref rect);

            //set event forwarder
            mEventForwardInputEmitter = new EventForwardInputEmitter(this);

            //set position and size
            Position  = new Point2(rect.left, rect.top);
            Size      = new Size(rect.right - rect.left, rect.bottom - rect.top);
            IsExisted = true;
        }
Ejemplo n.º 2
0
        private void CatchMessage(APILibrary.Win32.Message message)
        {
            //get mouse position
            Position <int> mousePosition()
            {
                return(new Position <int>(
                           APILibrary.Win32.Message.GetXFromLparam(message.lParam),
                           APILibrary.Win32.Message.GetYFromLparam(message.lParam)));
            }

            //get mouse wheel scroll offset
            int mouseWheelScrollOffset()
            {
                return(APILibrary.Win32.Message.HighWord(message.wParam));
            }

            void lockCursor()
            {
                APILibrary.Win32.Internal.SetCapture(mHandle);

                var position   = new APILibrary.Win32.Point();
                var clientRect = new APILibrary.Win32.Rect();

                APILibrary.Win32.Internal.GetClipCursor(ref mLastClipRect);
                APILibrary.Win32.Internal.ClientToScreen(mHandle, ref position);
                APILibrary.Win32.Internal.GetClientRect(mHandle, ref clientRect);

                var lockRect = new APILibrary.Win32.Rect()
                {
                    left   = position.x,
                    top    = position.y,
                    right  = position.x + clientRect.right - clientRect.left,
                    bottom = position.y + clientRect.bottom - clientRect.top
                };

                APILibrary.Win32.Internal.ClipCursor(ref lockRect);
            }

            void unLockCursor()
            {
                APILibrary.Win32.Internal.ReleaseCapture();

                APILibrary.Win32.Internal.ClipCursor(ref mLastClipRect);
            }

            switch ((APILibrary.Win32.WinMsg)message.type)
            {
            //sender event
            case APILibrary.Win32.WinMsg.WM_KEYUP: SenderEvent(new KeyBoardEvent(DateTime.Now, (KeyCode)message.wParam, false)); break;

            case APILibrary.Win32.WinMsg.WM_KEYDOWN: SenderEvent(new KeyBoardEvent(DateTime.Now, (KeyCode)message.wParam, true)); break;

            case APILibrary.Win32.WinMsg.WM_MOUSEMOVE: SenderEvent(new MouseMoveEvent(DateTime.Now, mousePosition())); break;

            case APILibrary.Win32.WinMsg.WM_LBUTTONUP: unLockCursor();
                SenderEvent(new MouseClickEvent(DateTime.Now, mousePosition(), MouseButton.Left, false)); break;

            case APILibrary.Win32.WinMsg.WM_MBUTTONUP: unLockCursor();
                SenderEvent(new MouseClickEvent(DateTime.Now, mousePosition(), MouseButton.Middle, false)); break;

            case APILibrary.Win32.WinMsg.WM_RBUTTONUP: unLockCursor();
                SenderEvent(new MouseClickEvent(DateTime.Now, mousePosition(), MouseButton.Right, false)); break;

            case APILibrary.Win32.WinMsg.WM_MOUSEWHEEL: SenderEvent(new MouseWheelEvent(DateTime.Now, mousePosition(), mouseWheelScrollOffset())); break;

            case APILibrary.Win32.WinMsg.WM_LBUTTONDOWN: lockCursor();
                SenderEvent(new MouseClickEvent(DateTime.Now, mousePosition(), MouseButton.Left, true)); break;

            case APILibrary.Win32.WinMsg.WM_MBUTTONDOWN: lockCursor();
                SenderEvent(new MouseClickEvent(DateTime.Now, mousePosition(), MouseButton.Middle, true)); break;

            case APILibrary.Win32.WinMsg.WM_RBUTTONDOWN: lockCursor();
                SenderEvent(new MouseClickEvent(DateTime.Now, mousePosition(), MouseButton.Right, true)); break;

            default: break;
            }
        }