TrackMouseEvent (user32)
Last changed: -156.145.34.220

.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError=true)]
static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    // C#    
    // Sets the hover time to 3sec and resets MouseEnter so the cursor does not have to
    // leave the control to hover again

        [DllImport("user32.dll")]
        static extern int TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
        [StructLayout(LayoutKind.Sequential)]
        public struct TRACKMOUSEEVENT
        {
            public UInt32 cbSize;
            public UInt32 dwFlags;
            public IntPtr hWnd;
            public UInt32 dwHoverTime;

            public TRACKMOUSEEVENT(UInt32 dwFlags, IntPtr hWnd, UInt32 dwHoverTime)
            {
                this.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));
                this.dwFlags = dwFlags;
                this.hWnd = hWnd;
                this.dwHoverTime = dwHoverTime;
            }
        }        

        protected override void OnMouseHover(EventArgs e)
        {            
            OnMouseEnter(e);
            base.OnMouseHover(e);
        }

        TRACKMOUSEEVENT tme; // Define it on the outside so you dont recreate it each time the mouse enters
        protected override void OnMouseEnter(EventArgs e)
        {            
            base.OnMouseEnter(e);
            tme = new TRACKMOUSEEVENT();            
            tme.hWnd = this.Handle;            
            tme.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT)); // make sure it gets correct size in different platforms
            tme.dwFlags = TME_HOVER;
            tme.dwHoverTime = 1000 * 3;
            TrackMouseEvent(ref tme);            
        }

Alternative Managed API:

The Control.MouseEnter, Control.MouseLeave and Control.MouseHover events.

Documentation