views:

35

answers:

1

I'm having the following code:

CMainFrame* pFrame = new CMainFrame;
if (!pFrame)
    return FALSE;
m_pMainWnd = pFrame;
// create and load the frame with its resources
pFrame->LoadFrame(IDR_APP_MAINFRAME,
    WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
    NULL);
// The one and only window has been initialized, so show and update it
pFrame->ShowWindow(SW_SHOWMAXIMIZED);

The problem is, when I press <ALT>, the menu(IDR_APP_MAINFRAME) will popup. How can I always hide the menu and do not response to presss?

I had heard this is due to an accelerator control in MFC, but I couldn't see the control in my project solution which is using VS2008..

A: 

In your CMainFrame override PreCreateWindow and destroy the menu. Try something like this:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
        if(cs.hMenu!=NULL)
        {
                ::DestroyMenu(cs.hMenu);
                cs.hMenu = NULL;
        }
        return CFrameWnd::PreCreateWindow(cs);
}
mmonem
I tried your way, however, it crashes when it proceed:void CFrameWnd::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)(hParentMenu = pParent->GetMenu()->GetSafeHmenu()) != NULL) //-->hereIs there a way to init the menu, but don't show it at all?
wengseng
@wengsenf: Why do you override `CFrameWnd::OnInitMenuPopu`?
mmonem
I din't overrde. It break at the line in mfc built in code.
wengseng
Strange! Anyway, try to add an empty handler for `WM_INITMENUPOPUP` message in your `CMainFrame`
mmonem