Click here to Skip to main content
Click here to Skip to main content

Tooltips for Menu Item and popup menuitem

By , 19 Nov 2003
 

Sample Image - menuitemtooltip.gif

Introduction

This article describes what is in my opinion the simplest and best way to add tool tips to the menu items. All you have to do is simply include the header file and call Create and hook the WM_MENUSELECT message.

Call this Create function in OnInitDialog or OnCreate functions of your main window

myMenuToolTip.Create(m_hWnd, _T("Sample Menu Text"), 
    AfxGetResourceHandle(), TTS_NOPREFIX | TTS_BALLOON 
         // play with this flags to get your own style of toolips
, _T("My Best Tool Tip Title") // title for the tooltips
);

When your window receives WM_MENUSELECT, call OnMenuSelect function to notify my helper class

myMenuToolTip.OnMenuSelect(nItemID, nFlags, hSubMenu);

Helper Class implementation

  1. Creates a tool tip window and adds the parent as tool to tooltip window
  2. Makes the tool as trackable tool
  3. On MenuSelect (Highlight) based on selected item, helper class activates the tooltip and positions it next selected menu item.
  4. On MenuSelect (Unhighlight) deactivates the tooltip

Instead of just calling OnMenuSelect you could handle the menu messages by looking at default implementation in the helper class

Note: Tip text is extracted from resource just like MFC/WTL extracts text for status bar messages.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

venu8000
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralTips can display off screenmemberR.D.H.19 Jan '05 - 5:20 
If a menu item is on the far right side of the monitor, the tip displays off screen!
GeneralIncorrect show for second, third etc. submenumemberEugene Pustovoyt16 Dec '03 - 3:03 
I'm try show tooltip for the second and third submenu in your demo. But a tooltip was shown in the incorrect place.
 
Best regards,
Eugene Pustovoyt
GeneralRe: Incorrect show for second, third etc. submenumembervenu800016 Dec '03 - 6:00 
Yes that has been fixed by replacing one parm for GetMenuItemRect.
 
Here is the fix:
Loom for GetMenuItemRect(hParent,..)
and replace with
GetMenuItemRect(NULL,..)
 
This should fix the problem.
Thanks
 

GeneralCan't work for dynamic menumemberdaveice10 Dec '03 - 21:32 
It doesn't work for a context menu.I mean when you right-click and track popup menu
GeneralNot bad!memberWREY24 Nov '03 - 22:29 
Simple, and to the point!
 
Keep up the good work, and you'll do better on your next article.
 
Good job.
 
Smile | :)
 
William
 
Fortes in fide et opere!
GeneralPaul di Lasciamembertopus20 Nov '03 - 23:45 
Man dont discover fresh water! Paul di Lascia in the November 2003 MSDN Magazine make the same thing in a much clear way. Look at http://msdn.microsoft.com/msdnmag/issues/03/11/default.aspx
GeneralVC7 DebugmemberAndrew Phillips18 Jan '05 - 21:12 
> Man dont discover fresh water!
 
What's wrong with discovering fresh water?!? I guess you mean don't reinvent the wheel.
 
Anyway thanks for the pointer to the di Lascia code. I found it very useful!!
 
I couldn't get the venu8000's example project to display the tips in debug builds (under VC7). (The release version works though.)
 
However, I need the debug version as I am making major chnages (dynamic tips that change at run-time). I will be using the Paul di Lascia code since it works in debug on VC7.

 
Andrew Phillips
aphillips @ expertcomsoft.com
GeneralTwo easy things to addmemberdog_spawn20 Nov '03 - 13:45 
You wrote:
Simple and best way to add tooltips to the menu items
 
Quite a claim! You need to justify this if you want people to take you seriously.
 
You wrote:
My helper class will take care of everything else from there
 
I think I am not alone in saying this: on Code Project visitors want to know what your helper class does and how it works. That kind of thing just makes your article more interesting and gives you credibility.
 
I am not going to download and use your code unless your article convinces me to do so.
GeneralRe: Two easy things to addmembervenu800020 Nov '03 - 14:44 
Take a look at helper class It is very simple and it would not require any credibility.
In any case I have also added some description about implementation about helper class.
GeneralRe: Two easy things to addmemberdog_spawn20 Nov '03 - 15:38 
venu8000 wrote:
it would not require any credibility
 
I'm sorry, but that is the most ridiculous thing I have read yet on codeproject.
 
Perhaps there is a communication issue here Roll eyes | :rolleyes:
 
Anyway, it is good to see you have improved the article slightly. Keep it up...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 20 Nov 2003
Article Copyright 2003 by venu8000
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid