Dynamic Tooltips for MenuItems |
Post Reply |
Author | |
mfproudman
Newbie Joined: 08 May 2008 Location: Canada Status: Offline Points: 8 |
Post Options
Thanks(0)
Posted: 02 July 2010 at 9:24am |
We would like to have dynamic tooltips associated with Toolbar and Menu items. The purpose would be to tell users why the update handler has turned a menu or toolbar selection on or off.
I have the obvious static resource-based tooltips working for MenuBars and Toolbars, but is there a way to change text dynamically, perhaps from the OnUpdateUI handler?
I have tried handling WM_XTP_CONTROLSELECTED. I get a pointer to the control and hence to the ID of the menu item, but SetTooltip() seems to have no effect. In the following, I get the TRACE, but not the tooltip (I get the static resource-based tooltip string):
LRESULT CMainFrame::OnXTPControlSelected(WPARAM wParam, LPARAM lParam) {
CXTPControl * ctrl = (CXTPControl *)wParam; if(!ctrl) return NULL;CString msg; msg.Format( "id=%d\n", ctrl->GetID());TRACE(msg); ctrl->SetTooltip(msg); return lParam;} Is this supported? Controlling at runtime the tooltip associated with a menu item must be possible; it seems a pretty obvious idea. Any comments appreciated, Mark Proudman
mfproudman@gmail.com
|
|
Mark Proudman
|
|
mfproudman
Newbie Joined: 08 May 2008 Location: Canada Status: Offline Points: 8 |
Post Options
Thanks(0)
|
Two points further to this post:
1. I made a mistake in the original post, and cut and pasted the wrong code.
Handling WM_XTP_CONTROLSELECTED works (almost - see point 2 below) with CXTPControl::SetTooltip() _when called from CMainFrame_ to update the tooltip on the application main menu (or a submenu thereof).
But it does not work when called to update a Context right-click popup menu invoked with TrackPopupMenu() from a view. In that case, I get my trace, but no tooltip. In other words, the following code is invoked, but puts no toolitp on the context menu:
LRESULT CMyView::OnXTPControlSelected(WPARAM wParam, LPARAM lParam) {
CXTPControl * ctrl = (CXTPControl *)wParam; if(!ctrl) return NULL; CString msg; msg.Format("id=%d\n", ctrl->GetID()); TRACE(msg); ctrl->SetTooltip(msg); return lParam; } Is there a way to get dynamic tool tips on a context menu?
2. Even when called from CMainFrame to update the application menu menu, the WM_XTP_CONTROLSELECTED message gets there late. (There is a forum post of 16 December 2009 on this, but no followup). WM_XTP_CONTROLSELECTED gets handled _after_ the tooltip is displayed, so the first tooltip the user sees is the _second last_ tooltip set with CXTPControl::SetTooltip().
Is there a way around this? Either another message (WM_XTP_CONTROL_ABOUT_TO_BE_SELECTED?), or a way of intercepting something like WM_XTP_INITMENU, so that a current and up to date tooltip can be provided?
I'm sure that more than one developer has wrestled with this.
Thanks for any input,
Mark Proudman
|
|
Mark Proudman
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |