Hover over the button to respond to Onmousehover, onmousemove, and OnMouseLeave

Source: Internet
Author: User
Tags cbtn

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

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.