Use _ trackmouseevent to capture wm_mouseleave and wm_mousehover messages

Source: Internet
Author: User

By default, the window does not respond to the wm_mouseleave and wm_mousehover messages. Therefore, use the _ trackmouseevent function to activate the two messages. After this function is called, when the mouse stays in the specified window for more than a certain period of time or leaves the window, the function will post the two messages to the specified window.

Usage:

1. Define a variable in the window class to identify whether to track the current mouse state. The reason for this definition is to avoid repeated wm_mousehover when the mouse is already on the form.
Bool_ Bmousetrack =True;

2. Call in onmousemove _ Trackmouseevent Function
If (_ bmousetrack)   // If allowedTrace, then.
{
Trackmouseevent Cstme;
Cstme. cbsize =Sizeof (Cstme );
Cstme. dwflags = Tme_leave | tme_hover;
Cstme. hwndtrack = M_hwnd ; // SpecifyTrackingWindow
Cstme. dwhovertime = 10; // The status is hover only when the mouse stays on the button for more than 10 ms
:: _ Trackmouseevent (& Cstme ); // Enable wm_mouseleave and wm_mousehover events for Windows
_ Bmousetrack = False ; // IfTracking, StopTracking
}

3. You can track the mouse status again in onmouseleave.
_ Bmousetrack =True;

4. Note: you must write the mappings between the two messages by yourself.
On_message (wm_mousehover, onmousehover)
On_message (wm_mouseleave, onmouseleave)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.