Re: Menu Not Available from Keyboard

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 12/31/04


Date: Fri, 31 Dec 2004 16:27:53 -0500

Yes, this is one of hte problems with dialog-based apps. There is also an MSDN article on
how to use keyboard menu shortcuts, but I can't find it in the latest MSDN (while they
still retain Win16 articles, many of the useful other articles seem to get purged. There
is a trick you have to do to make the shortcut keys work. But I spent a fair amount of
time doing MSDN searches and couldn't locate it. And I know I've seen it there.
                                        joe

On Thu, 30 Dec 2004 09:01:54 -0800, "Tom Serface" <tserface@msn.com> wrote:

>UPDATE_COMMAND_UI stuff doesn't work well for menus in a dialog. I have
>this problem with context (right click) menus and I've fixed it by
>implementing a handler for:
>
>ON_WM_INITMENUPOPUP()
>
>That looks like this:
>
>void CMyDialog::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
>{
> if (bSysMenu)
> return; // don't support system menu
>
> ASSERT(pMenu != NULL);
>
> // check the enabled state of various menu items
> CCmdUI state;
> state.m_pMenu = pMenu;
> ASSERT(state.m_pOther == NULL);
> ASSERT(state.m_pParentMenu == NULL);
> state.m_pParentMenu = pMenu; // parent == child for tracking popup
> state.m_nIndexMax = pMenu->GetMenuItemCount();
> for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
>state.m_nIndex++) {
> state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
> if (state.m_nID == 0)
> continue; // menu separator or invalid cmd - ignore it
> ASSERT(state.m_pOther == NULL);
> ASSERT(state.m_pMenu != NULL);
> state.m_pSubMenu = NULL;
> state.DoUpdate(this, false);
> }
>}
>
>This pumps the messages to the correct handlers right before the menu is
>popped up. I assume something like this would work for other kinds of menus
>in a dialog rather than just context menus.
>
>Tom
>
>"Frank Hickman [MVP]" <fhickman_NOSP@M_noblesoft.com> wrote in message
>news:ltLAd.56$Km.47@fe04.lga...
>> This is probably due to the handlers not being in available when your
>> other windows have the focus. You can do a few things to work around
>> this...write handlers for all the dialogs which call common code, write
>> UPDATE_COMMAND_UI handlers for the functions that keep them enabled but I
>> think they would still need some kind of link to the command code, or move
>> all the command code to the main frame window in which case the
>> functionality would always be available so you would probably need
>> UPDATE_COMMAND_UI handlers to disable functionality that is not available.
>> For instance, you would not want the save functionality if no document was
>> open.
>>
>> --
>> ============
>> Frank Hickman
>> Microsoft MVP
>> NobleSoft, Inc.
>> ============
>> Replace the _nosp@m_ with @ to reply.
>>
>>
>> "Jonathan Wood" <jwood@softcircuits.com> wrote in message
>> news:u6Ts8ng7EHA.2552@TK2MSFTNGP09.phx.gbl...
>>>I have a modeless dialog box (contained in some dockable windows in an MDI
>>> app).
>>>
>>> Mostly, it's working okay but when a control in the dialog box has the
>>> focus, the main window menu is unavailable by keyboard (Alt+F, etc. have
>>> no
>>> effect).
>>>
>>> I've modelled my code after some other applications and notice the menus
>>> in
>>> these applications work even when the dialogs have the focus. Does anyone
>>> have any suggestions on where I'd look to determine how to keep my menus
>>> working?
>>>
>>> Thanks!
>>>
>>> --
>>> Jonathan Wood
>>> SoftCircuits
>>> http://www.softcircuits.com
>>> Available for consulting: http://www.softcircuits.com/jwood/resume.htm
>>>
>>>
>>
>>
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: Menu Not Available from Keyboard
    ... > MSDN article on ... > still retain Win16 articles, many of the useful other articles seem to get ... >>UPDATE_COMMAND_UI stuff doesn't work well for menus in a dialog. ... >>This pumps the messages to the correct handlers right before the menu is ...
    (microsoft.public.vc.mfc)
  • Re: vtable issue
    ... The last one used to be on MSDN, but I can't find it right now. ... understand their policy about articles. ... I remember there were other articles like Jan Gray's one that explained common programming patterns useful with Windows. ... Because it's beyond any decent words. ...
    (microsoft.public.vc.language)
  • Re: Fields vs Properties vs Methods
    ... MSDN seems to use the term field loosely. ... > Find great Windows Forms articles in Windows Forms Tips and Tricks ... >> When you saw in past a record or a memory description graphical it was ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Polymorphism & Collections
    ... One of the better articles I've found to ... help me understand designing the different layers/tiers is this one on MSDN: ... business entities in the same layer as the business rules. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Define the Icon to custom file with custom extension..
    ... In article, "Deamond" ... If you look in MSDN there is an article entitled "Creating Shell Extension ... Handlers" which deal with the subject in some detail. ...
    (alt.comp.lang.borland-delphi)