Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC
  New Posts New Posts RSS Feed - Dynamic Tooltips for MenuItems
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Forum LockedDynamic Tooltips for MenuItems

 Post Reply Post Reply
Author
Message
mfproudman View Drop Down
Newbie
Newbie


Joined: 08 May 2008
Location: Canada
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote mfproudman Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic Tooltips for MenuItems
    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
Back to Top
mfproudman View Drop Down
Newbie
Newbie


Joined: 08 May 2008
Location: Canada
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote mfproudman Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2010 at 10:15am
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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.