一个类似QQ窗体自动上卷的程序(2)

[StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)]
        public struct TRACKMOUSEEVENT {
        public long cbSize;
        public long dwFlags;
        public long hwndTrack;
        public long dwHoverTime;
        }

private const int WM_MOUSEHOVER = 0x2a1;
        private const int WM_MOUSELEAVE = 0x2a3;
        private const int WM_MOUSEMOVE = 0x200;
        private const int TME_HOVER = 0x1;
        private const int WM_LBUTTONUP = 0x202;
        private const int WM_LBUTTONDOWN = 0x201;
        private const int VK_LBUTTON = 0x01; 

/// <summary>
        /// 消息处理函数
        /// </summary>
        /// <param></param>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

switch (m.Msg)
            {
                case WM_LBUTTONDOWN:
                    {
                        if (m.WParam.ToInt32() == VK_LBUTTON)
                        {
                            this._mouseDownPos = GetPointFromLPARAM(m.LParam.ToInt32());
                        }
                    }
                    break;
                case WM_LBUTTONUP:
                    QQForm_MouseUp();
                    break;
                case WM_MOUSELEAVE:
                    QQForm_MouseLeave();
                    break;
                case WM_MOUSEHOVER:
                    QQForm_MouseEnter();
                    break;
                case WM_MOUSEMOVE:
                    {
                        TRACKMOUSEEVENT msevnt = new TRACKMOUSEEVENT();
                        msevnt.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));
                        msevnt.dwFlags = TME_HOVER;
                        msevnt.hwndTrack = (long)this.Handle;
                        msevnt.dwHoverTime = 300;

if (m.WParam.ToInt32() == VK_LBUTTON)
                        {
                            Point newCursor = GetPointFromLPARAM(m.LParam.ToInt32());
                            this.Location = new Point(this.Location.X + newCursor.X - this._mouseDownPos.X,
                                this.Location.Y + newCursor.Y - this._mouseDownPos.Y);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
       
        /// <summary>
        /// 获得低16位值
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public static int GET_X_LPARAM(int lParam) { return (lParam & 0xffff); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpzsw.html