Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

TrackMouseEvent (user32)
 
.
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

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions