Showing Tool tips on controls

Source: Internet
Author: User
Ctooltipctrl can be used to attach Tool tips for controls. the Tool tips can be placed on any controls using addtool (), a member function of ctooltipctrl. this article explains how to show Tool tips for a command button which is placed on Dialog Box .

Tool tips are shown in a round rectangle adjacent to the controls. They are shown when the mouse cursor is placed on the control.

 

Tool tips on a dialog-ctooltipctrl:

    • Create a new dialog based MFC application. The article assumes the application name as mfcsample.
    • In the mfcsampledlg. h file, add a member variable for ctooltipctrl inside cmfcsampledlg class as follows.

Ctooltipctrl * m_tooltip;

    • Add a command button to the dialog box. Create a member variable for the button as m_testbutton.
    • In the oninitdialog function of the cmfcsampledlg class (mfcsampledlg. cpp) Add the following code.

M_tooltip = new ctooltipctrl ();
Enabletooltips (true );///// Missed line in the original paper. Without this line the code snippet does not work.
M_tooltip-> Create (this );

M_tooltip-> addtool (&M_testbutton, "Test button ");

M_tooltip-> activate (true );

    • The above Code adds a tool tip for the command button. If the mouse cursor is placed on the button, it shows a tool tip as "test button ".
    • More controls can be added with the tool tip as abve.
    • The following version of pretranslatemessage shocould be placed in mfcsampledlg. cpp, to override the default one.

Bool cmfcsampledlg: pretranslatemessage (MSG * PMSG)
{
// Todo: add your specialized code here and/or call the base class

If (m_tooltip! = NULL)
M_tooltip-> relayevent (PMSG );

Return cdialog: pretranslatemessage (PMSG );
}

The above pretranslatemessage version, ensures that Windows gets the comprehensions required for the Tool tips.

The above program creates the ctooltipctrl variable using the new operator. So the memory shoshould be freed at the end of the program by using the delete operator.

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.