The Wm_mouseleave and wm_mousehover of the edit box are used

Source: Internet
Author: User

Resources

Http://www.cnblogs.com/weiqubo/archive/2011/04/14/2016323.html

Recent work needs, need to customize the edit box, rewrite the edit box CEdit class.

I want to do one. When the mouse moves in the input box is highlighted, leaving time-varying back.

When you want to rewrite the Wm_mouseleave and wm_mousehover two messages, the mouse move in and out of the message is not executed.

The reason is that Windows do not respond to Wm_mouseleave and wm_mousehover messages by default, so use the _trackmouseevent function to activate these two messages. After this function is called, the function posts the two messages to the specified window when the mouse is over a specified window for more than a certain amount of time or after leaving the window.

How to use:
1. Define a variable in the dialog class to identify whether to track the current mouse state, the reason for this definition is to avoid the mouse is already on the form, a mobile mouse will repeatedly produce wm_mousehover.
BOOL _bmousetrack=true;


2. Call the _trackmouseevent function in OnMouseMove
if (_bmousetrack)//If tracing is allowed, then.
{
TrackMouseEvent Cstme;
cstme.cbsize = sizeof (CSTME);
Cstme.dwflags = tme_leave| Tme_hover;
Cstme.hwndtrack = m_hwnd;//Specify the window to be traced
Cstme.dwhovertime = 10; The mouse on the button to stay more than 10ms, it is considered the status of HOVER
:: _trackmouseevent (&CSTME); Turn on Windows Wm_mouseleave, Wm_mousehover event support


_bmousetrack=false; If it's been traced, stop tracking.
}

(#add excerpt from msdn:the _trackmouseevent function posts messages when the mouse pointer leaves a window or hovers over A window for a specified amount of time. This function calls trackmouseevent if it exists, otherwise it emulates it.)
3. Allow tracking of mouse state again in OnMouseLeave
_bmousetrack=true;


4. Note: These two messages are mapped to their own writing
On_message (Wm_mousehover,onmousehover)
On_message (Wm_mouseleave,onmouseleave)

Note: You can also use the following code in the PreTranslateMessage function to receive, do not need to write their own wm_mouselease and Wm_mousehover message response function (of course you have to write it yourself):
if (pmsg-> message==wm_mouseleave)
AfxMessageBox ("mouse Leave");

else if (pmsg->message = = wm_mousehover)

Afxmessagebos ("mouse Leave");


Return CDialog::P retranslatemessage (PMSG);

The Wm_mouseleave and wm_mousehover of the edit box are used

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.