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