 |
|
 |
Hi,
I have a popup-menu which is displayed OnRButtonDown() and after the menu is displayed and some
action is performed, I need to click with the left mouse button once somewhere in the window in
order to give it focus. After that, I can click on toolbars, menus, etc.
I've tried this approach, but I still have the focus issue.
Thanks.
|
|
|
|
 |
|
 |
This code simply grays out menu items based on the MFC command updates mechanism.
|
|
|
|
 |
|
 |
The Command Routing for Popup Menus work perfect if you give a handle to the CMainFrame Window to TrackPopupMenu! Thats all you need! Command Routing works fine in this case!
--
Martin Richter (MVP for C++) WWJD http://blog.m-ri.de
"A well-written program is its own heaven; a poorly written program is its own hell!" The Tao of Programming
|
|
|
|
 |
|
 |
I suppose but then you'll need knowledge of the commands in your mainframe right? Anything that allows you to have more control is good IMO. Also this was created many years ago, not sure if its been changed over the years.
|
|
|
|
 |
|
 |
No! Just give TrackPopupMenu AfxGetMainWnd as a parameter and that is sufficient. You have to know nothing about the main frame.
The command routing mechanism will pass the command on. So if you use this popup menu inside a view the corresponding command in View, document, mainframe, application will be found.
--
Martin Richter (MVP for C++) WWJD http://blog.m-ri.de
"A well-written program is its own heaven; a poorly written program is its own hell!" The Tao of Programming
|
|
|
|
 |
|
 |
Cool, nice to know, haven't actually done any MFC stuff in about 5 years, but if I ever use that ancient library again I'll keep it in mind
|
|
|
|
 |
|
 |
The following code doesn't appear to match the comments. It NEVER auto disables normal menu items.
// normal menu item, Auto disable if command is
// _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(pWnd, FALSE);
I think it should be instead:
// normal menu item, Auto disable if command is
// _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(pWnd, state.m_nID < 0xF000);
I couldn't find a nice #define for that 0xF000, but the justification is MFC Technical Notes: TN020: ID Naming and Numbering Conventions.
Once this change is made, my unimplemented dialog menus items come up nicely grayed.
-Jim
|
|
|
|
 |
|
 |
If you wonder why the ON_UPDATE_COMMAND_UI handlers do not work for popups, this is because the CMainFrame class handles the WM_INITPOPUPMENU message and polls the ON_UPDATE_COMMAND_UI handlers for the app/frame/doc/view in that order. (It does the same for toolbar buttons, but in such cases it does it in the OnIdle() function call)
When you do a regular popup menu, then unless the mainframe is the parent, the frame does not handle the WM_INITPOPUPMENU message and the ON_UPDATE_COMMAND_UI handlers to not get called.
Note also, that even if the CMainFrame is the parent window and you specify the TPM_NONOTIFY style in the call to TrackPopupMenu/Ex, then no WM_INITMENUPOPUP message is sent and the ON_UPDATE_COMMAND_UI handlers will also not get called.
What is proposed here is basically a copy of the CMainFrame::OnInitMenuPopup() handler code so that the ON_UPDATE_COMMAND_UI handlers get called as required.
But its a good implementation none the less.
If you vote me down, my score will only get lower
|
|
|
|
 |
|
 |
This works well but misses one small piece, which is the MFC logic that allows a popup child menu of the main menu to be modified (grayed, etc). The fix is to replace the code handling popup menus with the following: ... if (state.m_nID == (UINT)-1) { // possibly a popup menu, route to child menu if so CMenu* pSub=pPopupMenu->GetSubMenu(state.m_nIndex); if (pSub) { // this allows submenu to be modified state.m_pSubMenu = pSub; state.m_nID = pSub->GetMenuItemID(0); state.DoUpdate(pWnd,FALSE); // now recursively process items in it CmdRouteMenu(pWnd,pSub); } } ... For how to use this to enabled/disabled popups at runtime see http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0299/c++/c++0299.htm&nav=/msj/0299/newnav.htm
|
|
|
|
 |
|
 |
kam,
I think the link at the end of your post is not valid any longer. I poked around the web page for the MS System's Journal and tried to guess which article you were referencing. The link to my "guess" is posted below, FWIW.
http://www.microsoft.com/msj/0299/c/c0299.aspx[^]
--
-irrational john
|
|
|
|
 |
|
 |
Thanks, never thought of graying out the submenu item itself; but I can see it being useful!
|
|
|
|
 |
|
 |
Hi,
in my application I use a plug-in mechanism like described in http://www.codeproject.com/dll/plug-in.asp[^]. I managed it to display ToolBars from a plug-in in the MainApplication. But a menu provided by the plug-ins is missing there.
Does anybody know if it is possible to add a Submenu the the MainMenu by plug-in and only change the MessageHandler for this own Submenu??
Thanx for your help
Andreas Glaubitz
|
|
|
|
 |
|
 |
;PI have the same problem with the the MainMenu
|
|
|
|
 |
|
 |
Hi, I wish to know, how to I can make PopupMenu (or MainMenu) with drag and drop possibility (for menu items). I know, that I must SetMenuInfo with MNS_DRAGDROP and recieve WM_DRAGMENU, WM_MENUGETOBJECT messages. But I don't know how to implement DoDragDrop function and so on.
Majesty
|
|
|
|
 |
|
 |
I want to disable the menu item from view class. How to do it? For ex take file item in the menu. There is a pop up . Now if i want to disable save item at runtime, how do i do it?
|
|
|
|
 |
|
 |
I want to create menu as style in XP in Visual basic or Visual basic .NET.
|
|
|
|
 |
|
 |
visited following site:
http://www.vbaccelerator.com/home/VB/Code/Controls/Menus/index.asp
bye
|
|
|
|
 |
|
 |
I want to create a menu with file,edit.. as menu items.In file- menu selection there should be a pop up menu also(How to enable these new,open..under the file menu item)
sundar suresh
|
|
|
|
 |
|
 |
Thanks for posting this. It comes at the perfect time!
|
|
|
|
 |
|
 |
I agree completely. Just what I needed. Thank you!
-Carlos
|
|
|
|
 |
|
 |
I know, this question is not to this code. I have problems with normal, simple enabling and graying menu items.
Commands like:
AfxGetMainWnd()->GetMenu()->EnableMenuItem(ID_VIEW_TOOLBAR,MF_GRAYED|MF_BYCOMMAND);
or
AfxGetMainWnd()->GetMenu()->GetSubMenu(2)->EnableMenuItem(0,MF_GRAYED|MF_BYPOSITION);
or
AfxGetMainWnd()->GetMenu()->GetSubMenu(2)->EnableMenuItem(ID_VIEW_TOOLBAR,MF_GRAYED|MF_BYCOMMAND);
following with:
AfxGetMainWnd()->DrawMenuBar();
AfxGetMainWnd()->RedrawWindow();
didn't function (the items remained enabled), even though the Status of menu items has been changed (when I tried to call the some function for the second time, the return value (=previous state) was as I set it).
Noticable is, that command
AfxGetMainWnd()->GetMenu()->EnableMenuItem(0,MF_GRAYED|MF_BYPOSITION);
worked properly.
Could You help me with my problem, please?
Thank You very much..
|
|
|
|
 |
|
 |
I recently have been working on a project where it is not feasible for me to pass the main app window to TrackPopupMenu(..), and I needed to handle an UpdateCommandUI for a given set of popup menu's with one single function (using the ON_UPDATE_COMMAND_UI_RANGE macro).
I initially thought I was going to have to manually implement menu item enablement in my code by operating on the CMenu objects themselves, without the framework's rich support for this feature (what a nightmare!!).
After reading your article, I realized that this is just what was needed. You have really saved me a tremendous amount of work. Thank you!
|
|
|
|
 |
|
 |
Noel, I may be missing something here, but if you call TrackPopupMenu() specifying the main app window in the last parameter, then the update handlers are called for the popup as they would be for main menu items
|
|
|
|
 |
|
 |
It can be any window, usually for a dialog app say, and a tray icon right click popup menu, the main window is the one you need
|
|
|
|
 |
|
 |
>>Noel, I may be missing something here, but if you call TrackPopupMenu() specifying the main app window in the last parameter, then the update handlers are called for the popup as they would be for main menu items.
Actually, this is the idea, for example your hard work in adding OnUpdate messages for your main menu can be reused for your popup menu shortcuts that are also in the main window...basically a common way to set checkmarks and gray out/enable items
|
|
|
|
 |