MouseWheeMsg.cs
上传用户:fan366
上传日期:2022-07-21
资源大小:406k
文件大小:2k
源码类别:

浏览器

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. namespace OnePhoto
  6. {
  7.     public delegate void MouseWheelHandler(object sender, bool isDelta);
  8.     public class MouseWheeMsg:System.Windows.Forms.IMessageFilter
  9.     {
  10.         public event MouseWheelHandler MouseWheel;
  11.         protected virtual void OnMouseWheel(bool isDelta)
  12.         {
  13.             if (MouseWheel != null)
  14.                 MouseWheel(this, isDelta);
  15.         }// end viod 
  16.         private const int WM_MOUSEWHEEL = 0x020A;
  17.         /// <summary>
  18.         /// 定义句柄
  19.         /// </summary>
  20.         private bool m_HandleType;
  21.         /// <summary>
  22.         /// 设置是窗体句柄 还是控件句柄
  23.         /// </summary>
  24.         public bool SetHandleType
  25.         {
  26.             set
  27.             {
  28.                 this.m_HandleType = value;
  29.             }
  30.         }// end Form;
  31.         public MouseWheeMsg()
  32.         {
  33.             //
  34.             // TODO: 在此处添加构造函数逻辑
  35.             //
  36.             this.m_HandleType = true;
  37.         }
  38.         /// <summary>
  39.         /// 如果键入
  40.         /// </summary>
  41.         /// <param name="m"></param>
  42.         /// <returns></returns>
  43.         public bool PreFilterMessage(ref Message m)
  44.         {
  45.             switch (m.Msg)
  46.             {
  47.                 case WM_MOUSEWHEEL:
  48.                     if (this.m_HandleType)
  49.                     {
  50.                         //Type mytype = this.m_MouseEvent.GetType();
  51.                         //this.m_MouseEvent = (System.Windows.Forms.MouseEventArgs)m.GetLParam(mytype);
  52.                         if (m.WParam.ToInt32() > 0)
  53.                         {
  54.                             OnMouseWheel(true);
  55.                         }// end if
  56.                         else
  57.                         {
  58.                             OnMouseWheel(false);
  59.                         }// end if
  60.                         return true;
  61.                     }
  62.                     break;
  63.             }// end switch
  64.             return false;
  65.         }
  66.     }
  67. }