To add the tooltip function to the static text, follow these steps:
(1) define the ctooltipctrl object m_tooltip in the header file;
Ctooltipctrl m_tooltip;
The msdn description of ctooltipctrl is as follows:
TheCtooltipctrlClass encapsulates the functionality of a "tool tip control," a small pop-up window that displays a single line of text describing the purpose of a tool in an application. A "tool" is either a window, such as a child window or control, or an application-defined rectangular area within a window's client area. A tool tip is hidden most of the time, appearing only when the user puts the cursor on a tool and leaves it there for approximately one-half second. the tool tip appears near the cursor and disappears when the user clicks a mouse button or moves the cursor off the tool.
CtooltipctrlProvides the functionality to control the initial time and duration of the tool tip, the margin widths surrounding the tool tip text, the width of the tool tip window itself, and the background and text color of the tool tip. A single tool tip control can provide information for more than one tool.
(2) Call the member functions create and addtool.
Bool create (cwnd * Pparentwnd,DWORD Dwstyle=0 );
Return Value
Nonzero ifCtooltipctrlObject is successfully created; otherwise 0.
Parameters
Pparentwnd
Specifies the tool tip control's parent window, usuallyCdialog. It must not beNull.
Dwstyle
Specifies the tool tip control's style. apply any combination of control styles needed to the control.
Bool addtool (cwnd * Pwnd, Uint Nidtext, Lpcrect Lprecttool = NULL, uint Nidtool = 0 );
Bool addtool (cwnd * Pwnd, Lpctstr Lpsztext = Lpstr_textcallback, lpcrect Lprecttool = NULL, uint Nidtool = 0 );
Return Value
Nonzero if successful; otherwise 0.
Parameters
Pwnd
Pointer to the window that contains the tool.
Nidtext
ID of the string resource that contains the text for the tool.
Lprecttool
Pointer toRect structure containing coordinates of the tool's bounding rectangle. The coordinates are relative to the upper-left corner of the client area of the window identifiedPwnd.
Nidtool
ID of the tool.
Lpsztext
Pointer to the text for the tool. If this parameter contains the valueLpstr_textcallback,Ttn_needtextNotification messages go to the parent of the window thatPwndPoints.
M_tooltip.create (this); // create an object
M_tooltip.addtool (getdlgitem (idc_btn_playstop), "connection"); // lianjie button prompt
M_tooltip.addtool (getdlgitem (idc_check_view), "Local preview"); // button prompt
M_tooltip.addtool (getdlgitem (idc_btn_bmpcapture), "BMP screenshot"); // button prompt
M_tooltip.addtool (getdlgitem (idc_btn_localrec), "Local Video"); // button prompt
M_tooltip.addtool (getdlgitem (idc_btn_talk), "voice intercom"); // button prompt
M_tooltip.addtool (getdlgitem (idc_btn_reset), "restart device"); // button prompt
M_tooltip.addtool (getdlgitem (idcancel), "exit system"); // button prompt
M_tooltip.addtool (getdlgitem (idc_btn_clear), "clear message"); // The button prompts,
M_tooltip.setdelaytime (200 );
M_tooltip.settiptextcolor (RGB (0, 0, 0); // you can specify the font color.
M_tooltip.settipbkcolor (RGB (255,255,255); // you can specify the background color.
M_tooltip.activate (true );
(3) Add the virtual function pretranslatemessage
Bool claump4testdlg: pretranslatemessage (MSG * PMSG)
{
// Todo: add your specialized code here and/or call the base class
Switch (PMSG-> message)
{
Case wm_mousemove:
M_tooltip.relayevent (PMSG );
}
Return cdialog: pretranslatemessage (PMSG );
}