VC + + class Cmfectooltip to realize the floating prompt effect of window

Source: Internet
Author: User

Reference article: http://www.codefans.net/articles/1863.shtml

SOURCE Download: Http://pan.baidu.com/s/1sjt0jEH

VC + + make floating mouse prompts, when the mouse cursor on a program control, to know the function of the control, the best way is to pop up a prompt box to display this information. This example is to show how to make a floating mouse hint. Compile and run this sample program as shown in. When the mouse cursor is placed on a control, a prompt is displayed, and the background color can be set in the program.

There is a class Cmfectooltip can implement the floating mouse prompt function. This class captures the mouse information and, if the current mouse cursor position has a control that needs to display the prompt, displays the prompt window in the appropriate location. Using this class is simple. You first create an object of the class, and then you pass the ID of the control that you want to display the cue bar to, and information such as the color of the text and cue window that you want to display one by one to it, and then just display it when the mouse moves. The program code is:
(1) Generate dialog-based application InfoTip via AppWizard.
(2) To add a few controls to the dialog box, this example adds static text boxes, edit boxes, CComboBox controls, and buttons whose IDs are Idc_text1, idc_edit1, Idc_combo1, Idc_button1, respectively.
(3) Add the member variable m_tooltip of the Cmfectooltip type to the dialog box.
(4) Tell the Cmfectooltip object all the control information that needs to be displayed, and complete it in the OnInitDialog () function of the dialog box. The code is as follows:

M_tooltip.create (this);
CStringArray Strainfo;

Strainfo.removeall ();
Strainfo.add ("Test Control");
Strainfo.add ("Test Control2");
M_tooltip.addcontrolinfo (Idc_static, Strainfo, RGB (255,255,0));

(5) Overload message response: 1. Overloading messages in a DLG file

{{afx_virtual (CINFOTIPDLG)
Public
Virtual BOOL PreTranslateMessage (msg* pMsg);
Protected
virtual void DoDataExchange (cdataexchange* pDX); DDX/DDV Support
}}afx_virtual

2. Add and then capture the WM_MOUSEMOVE message in the PreTranslateMessage (MSG *pmsg) function of the dialog box with the following code:

BOOL Ctestdlg::P retranslatemessage (msg* pMsg)
{
if (pmsg->message = = wm_mousemove)
{
Point pt = pmsg->pt;
ScreenToClient (&PT);
M_tooltip.showtooltip ((CPoint) PT);
}
Return CDialog::P retranslatemessage (PMSG);
}

VC + + class Cmfectooltip to realize the floating prompt effect of window

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.