Print Page | Close Window

Dynamic Tooltips for MenuItems

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Visual C++ MFC
Forum Description: Topics related to Codejock Visual C++ MFC products
URL: http://forum.codejock.com/forum_posts.asp?TID=16904
Printed Date: 21 November 2024 at 12:37pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Dynamic Tooltips for MenuItems
Posted By: mfproudman
Subject: Dynamic Tooltips for MenuItems
Date 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



Replies:
Posted By: mfproudman
Date 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
mailto:mfproudman@gmail - mfproudman@gmail
 


-------------
Mark Proudman



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net