But Zan that is what I do for my right-click context menus. We have our own TrackPopupMenu on our frame that takes in a CMenu. If the frame is the tracking window, I get the command bars object from the frame and obtain the command bar options (to set bShowContextMenuAccelerators to TRUE) and also so I can pass in the TPM_RETURNCMD flag since CJ context menus call SendMessage instead of PostMessage (Send versus Post causes us all sorts of problems).
If the frame is not the tracking window (we have params to tell us that) I create a new CXTPCommandBars object and set the site to the tracking window. I set up a theme and then give the new cbars an image manager (to avoid CJ going to the frames image manager). I get the tooltip context from the cbars object I created and initialize it to our specifications. Finally I get the options and if an input flag indicates tips are wanted, I get the options from the cbars object I created and set bShowPopupBarToolTips to TRUE.
We also have an app setting that allows the user to turn off all tipping. If that flag is set, I ignore the caller's flag and honor the global setting and bShowPopupBarToolTips is set to FALSE.
This works for me. All our shortcut/context/right-click menu invokation calls now go through my frame's method and I either get tooltips on the shortcut menur or don't get them based on my call to set the option. Here is the code I go thru when I detect the caller does NOT want the frame to track the menu. In such cases it is up to the caller to provide the tip strings and images by handling WM_XTP_INITCOMMANDSPOPUP if the menu contains "command" IDs that are not known to our frame window.
CRuntimeClass* pCommandBarsClass = RUNTIME_CLASS(CXTPCommandBars);
CXTPCommandBars* pCommandBars = (CXTPCommandBars*) pCommandBarsClass->CreateObject();
ASSERT(pCommandBars);
if (!pCommandBars)
return FALSE;
...
pCommandBars->SetTheme(xtpThemeRibbon);
if( (Options & JSetSiteToMenuOwner) && pWnd && pWnd->GetSafeHwnd() )
{
// variable table flashes too much if site is set to its frame so we
// added the new option to force the site to the tracking/owner window.
// The var table can leave a bit of "trash" on the bottom edge if the
// user right-clicks a lot and fast and we decided that is better than
// the excessive flashing due to the var table updating.
pCommandBars->SetSite(pWnd);
}
else if( pWnd )
{
CFrameWnd* pFrame = pWnd->GetParentFrame();
if( pFrame != this )
{
if( pFrame )
{
pCommandBars->SetSite(pFrame);
}
else
{
// out of options. Dennis said the hyperlink command in draft has no parent frame and that causes an exception.
pCommandBars->SetSite( this);
}
}
else
{
//pCommandBars->SetSite(pWnd);
pCommandBars->SetSite( this);
}
}
else
{
// out of options. Dennis said the hyperlink command in draft has no parent frame and that causes an exception.
pCommandBars->SetSite( this);
}
pCommandBars->SetImageManager(new CXTPImageManager()); // Keeps icons from appearing due to usage of the frames command bars image manager
// Implement a message handler for the CodeJock WM_XTP_INITCOMMANDSPOPUP notification in ComamndBars.
// See \Samples\CommandBars\Notifications for an example. Or see x:\dsl\src\dcx\dimcmd\dev\skdimrib.cpp for
// and example that gets the notification and then calls skmoddim.cpp where icons, tooltips and descriptions are added.
// To display the prompts listen to WM_SETMESSAGESTRING and then call SetPrompt(). Again, see the skmoddim.cpp
// and skdimrib.cpp file for an example. And no, CodeJock does not seem to use the description when setting the
// prompt. And if the ID of the control is not part of the current resource module chain, CodeJock will call send
// the WM_SETMESSAGESTRING with the lparam set to some string saying something like "the description for cmd xxx is
// not available".
CXTPToolTipContext* pTipContext = pCommandBars->GetToolTipContext();
if( pTipContext )
{
InitializeToolTipContext( pTipContext );
}
CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();
if( pOptions )
{
pOptions->bDisableCommandIfNoHandler = Options & JDisableCommandIfNoHandler ? TRUE:FALSE;
if( GetDisplayTooltips() )
{
pOptions->bShowPopupBarToolTips = Options & JShowToolTips ? TRUE:FALSE;
}
else
{
// Frame rules supreme.
pOptions->bShowPopupBarToolTips = FALSE;
}
pOptions->bShowContextMenuAccelerators = TRUE;
}
bSelected = pCommandBars->TrackPopupMenuEx(pMenu, nFlags, xPos, yPos, pWnd, lptpm);
pCommandBars->InternalRelease(); // delete the object
You may not be getting tips if your site is not your frame and the window that is the site does not implement tipping in the standard way and does not respond to WM_XTP_INITCOMMANDSPOPUP.
|