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