Re: Is this an MFC bug?
Nice workaround. But there is also room for improvement, in order to reduce code duplicates this workaround can be inserted only once in your main application class derived from CWinAppEx, e.g.:
class CApplication : public CWinAppEx { ... };
extern CApplication theApp;
.....
BOOL CApplication::PreTranslateMessage(MSG* pMsg) {
BOOL handled = FALSE;
if(WM_SYSCOMMAND == pMsg->message
|| WM_KEYDOWN == pMsg->message
|| WM_CHAR == pMsg->message) {
CMFCPopupMenu* activeMenu = CMFCPopupMenu::GetActiveMenu();
if(nullptr != activeMenu) {
activeMenu->SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
handled = true;
}
}
if(!handled) {
handled = __super::PreTranslateMessage(pMsg);
}
return handled;
}
Cheers
On Sunday, April 10, 2011 12:26:36 PM UTC-4, David Webber wrote:
Using the new CWinAppEx class I launch a context menu (from my view class)
with
CContextMenuManager *pContextMenuManager = pApp->GetContextMenuManager();
pContextMenuManager->TrackPopupMenu( hMenu, pt.x, pt.y, this );
(
or alternatively
pContextMenuManager->ShowPopupMenu( hMenu, pt.x, pt.y, this, TRUE );
)
The context menu comes up fine and the commands built into hMenu work fine
but...
While, clicking with the mouse on a window menu, toolbar button, or in the
view dismisses the context menu, using a keyboard shortcut to a command
doesn't. In particular, not even the Escape key dismisses it.
How do I get rid of the thing without using the mouse?
Dave
-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm