Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Need help with TrackPopupMenu
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Need help with TrackPopupMenu

 Post Reply Post Reply
Author
Message
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 899
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Topic: Need help with TrackPopupMenu
    Posted: 23 January 2008 at 12:25pm
I have a dialog box that wants to track a popup menu. The menu is specified in a menu resource so I use a CMenu to load the resource. Then I call CXTPCommandBars::TrackPopupMenu.
 
But I have a problem with where messages go. I can get the WM_COMMAND message to be directed to the dialog. However, the OnCmdMsg function is invoked on my main frame (probably because it owns the dialog).
 
Also I am seeing icons being added to the popup menu that are incorrect because the dialog has its own command IDs on its menu and some of those IDs happen to be IDs used by the frame on its CXTPRibbonBar (incorrect tooltips are displayed too).
 
I have tried both the static and non-static TrackPopupMenu functions. I have tried TrackPopupMenuEx. I have tried setting each CWnd* arg to the dialog and setting each to the dialog while the other I set to NULL. I have tried passing in the frame's command bars pointer as the last arg and NULL for that arg (for the static methods). I believe I have exhausted all the various combinations and still I cannot get the OnCmdMsg call from being made on my frame window.
 
How do I get TrackPopupMenu or TrackPopupMenuEx to work correctly with the dialog?
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 23 January 2008 at 1:40pm
Hello,
 
problem not in TrackPopupMenu. I bet you will see same if will use standard TrakPopupMenu.
 
Check code of CDialog::OnCmdMsg and you will understand.
solution is to override this method and don't call CDialog's version.
but I recommend clean up your Ids and don't use same values for dialog and frame.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 899
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 23 January 2008 at 3:56pm
That's the rub. I was using CMenu::TrackPopupMenu and changed to use the CJ code. If I go thru the original code and set breakpoints in the CDialog::OnCmdMsg, no calls are made when I invoke CMenu::TrackPopupMenu.
 
That is, CDialog::OnCmdMsg call is only made when I use the command bars class to track the menu.
 
My experience with CMenu::TrackPopupMenu is that the tracking window gets a WM_INITMENUPOPUP message (as well as other menu messages like WM_MENUSELECT). When Windows sends the WM_INITPOPUPMENU message, we can spin thru the menu and enable/disable items, add bit maps etc (if we implement the handler that is). CJ does not seem to ever use that paradigm with its popup menu tracking. I believe this is the difference.
 
Some of our code prepares the menu before calling TrackPopupMenu. That is, instead of reacting to WM_INITMENUPOPUP, we load the menu from a resource file (or build it at runtime). We then enable/disable items and also add a bitmap to the menu using SetMenuItemBitmaps.
 
By the way, instead of using the CJ frame window's command bars object, I created my own and set the site to the dialog box. I can change the code for each tracking object to resolve the OnCmdMsg problem. But I have another issue you did not comment on.
 
How do I prevent CJ from putting the (incorrect) icons on the popup menu?
 
The command bars object I created has no image manager but I called SetImageManager(NULL) to no avail (wrong bitmaps still appear).
 
Also, for what its worth, I can use the TPM_NONOTIFY message, which shuts down OnCmdMsg calls altogether. So between that flag and having dialogs and other windows implement OnCmdMsg, the icon issue is all that remains.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 24 January 2008 at 12:59am
Hi,
 
There is ON_XTP_INITCOMMANDSPOPUP notification in ComamndBars. See \Samples\CommandBars\Notifications .
 
To create isolated ImageManager call
 
pCommandBars->SetImageManager(new CXTPImageManager()); - it this commandbars will use own images.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
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.047 seconds.