![]() |
Need help with TrackPopupMenu |
Post Reply ![]() |
Author | |
rdhd ![]() Senior Member ![]() ![]() Joined: 13 August 2007 Location: United States Status: Offline Points: 899 |
![]() ![]() ![]() ![]() ![]() 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?
|
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
rdhd ![]() Senior Member ![]() ![]() Joined: 13 August 2007 Location: United States Status: Offline Points: 899 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
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 |