using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VSoft.Prams
{
    public delegate void MouseMovedEvent();
    public delegate void MouseMDownEvent();
    public delegate void MouseMUpEvent();
    public class GlobalMouseHandler : IMessageFilter
    {
        private const int WM_MOUSEMOVE = 0x0200;
        private const int WM_MBUTTONDOWN = 0x0207;
        private const int WM_MBUTTONUP = 0x0208;
        public event MouseMovedEvent TheMouseMoved;
        public event MouseMDownEvent TheMouseMDown;
        public event MouseMUpEvent TheMouseMUp;
        #region IMessageFilter Members
        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg == WM_MOUSEMOVE)
                if (TheMouseMoved != null)
                    TheMouseMoved();
            if (m.Msg == WM_MBUTTONDOWN)
                if (TheMouseMDown != null)
                    TheMouseMDown();
            if (m.Msg == WM_MBUTTONUP)
                if (TheMouseMUp != null)
                    TheMouseMUp();
            // Always allow message to continue to the next filter control
            return false;
        }
        #endregion
    }
}
