Ejemplo n.º 1
0
        protected override void WndProc(ref Message m)
        {
            NativeEnums.WM msg = (NativeEnums.WM)m.Msg;

            if (msg == NativeEnums.WM.NCCALCSIZE)
            {
                return;
            }
            else if (msg == NativeEnums.WM.WINDOWPOSCHANGED)
            {
                blockCP = true;
                base.WndProc(ref m);
                blockCP = false;

                return;
            }

            base.WndProc(ref m);
        }
Ejemplo n.º 2
0
        protected override void WndProc(ref Message m)
        {
            NativeEnums.WM msg = (NativeEnums.WM)m.Msg;

            if (msg == NativeEnums.WM.SYSCOMMAND)
            {
                NativeEnums.SCType sc = (NativeEnums.SCType)m.WParam.ToInt32();

                if (sc == NativeEnums.SCType.SC_MINIMIZE)
                {
                    OnMinimize();
                }
                else if (sc == NativeEnums.SCType.SC_RESTORE)
                {
                    OnRestore();
                }
            }

            base.WndProc(ref m);
        }
Ejemplo n.º 3
0
 public extern static bool PostMessage(IntPtr hWnd, NativeEnums.WM wMsg, IntPtr wParam, IntPtr lParam);
Ejemplo n.º 4
0
 public static extern IntPtr SendMessage(IntPtr hWnd, NativeEnums.WM wMsg, bool wParam, int lParam);
Ejemplo n.º 5
0
 public static extern IntPtr SendMessage(IntPtr hWnd, NativeEnums.WM wMsg, IntPtr wParam, IntPtr lParam);
Ejemplo n.º 6
0
        protected override bool ProcessEvent(IntPtr wParam, IntPtr lParam)
        {
            bool handled = false;

            NativeEnums.WM message = (NativeEnums.WM)wParam;

            if (hooker.GetType() == typeof(GlobalHook))
            {
                NativeStructs.KBDLLHOOKSTRUCT khStruct = (NativeStructs.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(NativeStructs.KBDLLHOOKSTRUCT));
                //raise KeyDown
                if (message == NativeEnums.WM.KEYDOWN || message == NativeEnums.WM.SYSKEYDOWN)
                {
                    OnKeyDown(khStruct.vkCode, ref handled);
                }
                // raise KeyPress
                if (message == NativeEnums.WM.KEYDOWN)
                {
                    OnKeyPress((uint)khStruct.vkCode, (uint)khStruct.scanCode, (uint)khStruct.flags, ref handled);
                }
                // raise KeyUp
                if (message == NativeEnums.WM.KEYUP || message == NativeEnums.WM.SYSKEYUP)
                {
                    OnKeyUp(khStruct.vkCode, ref handled);
                }
            }
            else
            {
                const uint maskKeydown  = 0x40000000;        // for bit 30
                const uint maskKeyup    = 0x80000000;        // for bit 31
                const uint maskScanCode = 0xff0000;          // for bit 23-16

                int vkCode = wParam.ToInt32();

                uint flags = 0u;
                if (Utilities.Is64BitApplication())
                {
                    flags = Convert.ToUInt32(lParam.ToInt64());
                }
                else
                {
                    flags = (uint)lParam.ToInt64();
                }

                bool wasKeyDown = (flags & maskKeydown) > 0;
                //bit 31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
                bool isKeyReleased = (flags & maskKeyup) > 0;

                int scanCode = checked ((int)(flags & maskScanCode));

                if (!isKeyReleased)
                {
                    OnKeyDown(vkCode, ref handled);
                    OnKeyPress((uint)vkCode, (uint)scanCode, flags, ref handled);
                }
                if (isKeyReleased)
                {
                    OnKeyUp(vkCode, ref handled);
                }
            }
            return(handled);
        }
Ejemplo n.º 7
0
        protected override bool ProcessEvent(IntPtr wParam, IntPtr lParam)
        {
            NativeStructs.MSLLHOOKSTRUCT mouseHookStruct = (NativeStructs.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(NativeStructs.MSLLHOOKSTRUCT));

            MouseButtons button     = MouseButtons.None;
            short        mouseDelta = 0;

            NativeEnums.WM message = (NativeEnums.WM)wParam;

            switch (message)
            {
            case NativeEnums.WM.LBUTTONDOWN:
            case NativeEnums.WM.LBUTTONUP:
            case NativeEnums.WM.LBUTTONDBLCLK:
                button = MouseButtons.Left;
                break;

            case NativeEnums.WM.RBUTTONDOWN:
            case NativeEnums.WM.RBUTTONUP:
            case NativeEnums.WM.RBUTTONDBLCLK:
                button = MouseButtons.Right;
                break;

            case NativeEnums.WM.MBUTTONDOWN:
            case NativeEnums.WM.MBUTTONUP:
            case NativeEnums.WM.MBUTTONDBLCLK:
                button = MouseButtons.Middle;
                break;

            case NativeEnums.WM.MOUSEWHEEL:
                mouseDelta = (short)((mouseHookStruct.mouseData >> 16) & 0xffff);
                break;

            default:
                break;
            }

            //double clicks
            int clickCount = 0;

            if (button != MouseButtons.None)
            {
                if (message == NativeEnums.WM.LBUTTONDBLCLK || message == NativeEnums.WM.RBUTTONDBLCLK)
                {
                    clickCount = 2;
                }
                else
                {
                    clickCount = 1;
                }
            }

            //generate event
            MouseEventArgs e = new MouseEventArgs(button, clickCount, mouseHookStruct.pt.X, mouseHookStruct.pt.Y, mouseDelta);

            switch (message)
            {
            case NativeEnums.WM.LBUTTONDOWN:
            case NativeEnums.WM.RBUTTONDOWN:
            case NativeEnums.WM.MBUTTONDOWN:
                MouseDown.RaiseEvent(this, e);
                break;

            case NativeEnums.WM.LBUTTONUP:
            case NativeEnums.WM.RBUTTONUP:
            case NativeEnums.WM.MBUTTONUP:
                MouseUp.RaiseEvent(this, e);
                MouseClick.RaiseEvent(this, e);
                break;

            case NativeEnums.WM.LBUTTONDBLCLK:
            case NativeEnums.WM.RBUTTONDBLCLK:
            case NativeEnums.WM.MBUTTONDBLCLK:
                MouseDoubleClick.RaiseEvent(this, e);
                break;

            case NativeEnums.WM.MOUSEWHEEL:
                MouseWheel.RaiseEvent(this, e);
                break;

            case NativeEnums.WM.MOUSEMOVE:
                MouseMove.RaiseEvent(this, e);
                break;
            }

            return(false);
        }