1. Building an MFC program
2. Add button, Idc_button1
3. Add class, directly right-click control can not add CButton derived classes, if you want to add, you can only select the project root, right-click Add Class, MFC Class-->MFC Class Wizard--select inherit CButton.
4. Add a variable, check the button, right-click Add variable, MBT1, type cbtn//No this variable is not possible, I tried n times did not succeed, lack of this no response
5. Open the Class Wizard to add messages Onmousehover, OnMouseMove, and OnMouseLeave under class cbtn
6. Add bool m_btracking under public btn.h;
In Btn.cpp, add m_btracking=0;//initialization to the class's constructor, and the added message corresponds to the following, and the function is to open the Web page when the cursor hovers 1 on the button:
void Cbtn::onmousehover (UINT nflags, CPoint Point)
{
TODO: Add Message Handler code and/or call default values here
ShellExecute (0, NULL, _t ("http://hao.360.cn"), NULL, NULL, sw_normal);
M_btracking = false;
Cbutton::onmousehover (nflags, point);
}
void Cbtn::onmousemove (UINT nflags, CPoint Point)
{
TODO: Add Message Handler code and/or call default values here
if (!m_btracking)
{
TrackMouseEvent tme;
tme.cbsize = sizeof (trackmouseevent);
Tme.dwflags =tme_hover;//the message to trigger
Tme.hwndtrack = this->m_hwnd;
Tme.dwhovertime = 1000;//If this parameter is not set, the MouseHover cannot be triggered
if (:: _trackmouseevent (&tme))//mouseleave| MouseHover message triggered by this function
{
:: _trackmouseevent (&TME);
M_btracking = true;
}
}
Cbutton::onmousemove (nflags, point);
}
void Cbtn::onmouseleave ()
{
TODO: Add Message Handler code and/or call default values here
M_btracking = false;
Cbutton::onmouseleave ();
}
Reference http://blog.chinaunix.net/uid-26275986-id-3877610.html
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hover over the button to respond to Onmousehover, onmousemove, and OnMouseLeave