Exemplo n.º 1
0
 public static extern bool TrackMouseEvent(ref TrackMouseEvent lpEventTrack);
        protected override IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
        {
            switch (message)
            {
                #region mouse

            case WindowMessage.MOUSEMOVE:
            {
                if (!_mouseTracking)
                {
                    var tme = new TrackMouseEvent(TrackMouseEventFlags.TME_LEAVE, Handle);
                    if (Functions.TrackMouseEvent(ref tme))
                    {
                        _mouseTracking = true;
                    }
                }
            }
            break;

            case WindowMessage.MOUSEACTIVATE:
                System.Diagnostics.Debug.WriteLine("MOUSEACTIVATE.");
                break;

            case WindowMessage.MOUSELEAVE:
                _mouseTracking = false;
                System.Diagnostics.Debug.WriteLine("MOUSELEAVE.");
                break;

            case WindowMessage.LBUTTONDOWN:
                //HasKeyboardFocus = true;
                System.Diagnostics.Debug.WriteLine("LBUTTONDOWN.");
                break;

                #endregion

                #region keyBoard

            case WindowMessage.KEYDOWN:
            case WindowMessage.SYSKEYDOWN:
                System.Diagnostics.Debug.WriteLine("KEYDOWN.");
                OnKeyDown(VirtualKeyToKeyTranslator.Translate((VirtualKey)wParam.ToInt32()));
                break;

            case WindowMessage.KEYUP:
            case WindowMessage.SYSKEYUP:
                System.Diagnostics.Debug.WriteLine("KEYUP.");
                OnKeyUp(VirtualKeyToKeyTranslator.Translate((VirtualKey)wParam.ToInt32()));
                break;

                #endregion

            case WindowMessage.SETFOCUS:
                System.Diagnostics.Debug.WriteLine("SETFOCUS.");
                break;

            case WindowMessage.KILLFOCUS:
                System.Diagnostics.Debug.WriteLine("KILLFOCUS.");
                break;

            case WindowMessage.ACTIVATE:
                System.Diagnostics.Debug.WriteLine("ACTIVATE.");
                break;

            case WindowMessage.ERASEBKGND:
                return(IntPtr.Zero);

                break;

            case WindowMessage.PAINT:
                Draw();
                break;

            case WindowMessage.WINDOWPOSCHANGING:
                break;

            case WindowMessage.CLOSE:
                Functions.DestroyWindow(Handle);
                break;

            case WindowMessage.DESTROY:
                Functions.PostQuitMessage(0);
                break;
            }

            return(Functions.DefWindowProc(handle, message, wParam, lParam));
        }