需求:文檔/視圖架構下隱藏 `CMainFrame` 頂部菜單欄。
// CMainFrame::OnCreate
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {
if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1;
SetMenu(NULL); // 關鍵:移除菜單
return 0;
}
// CWinApp::InitInstance
BOOL CMyApp::InitInstance() {
// ... 標準初始化 ...
pMainFrame->m_hMenuDefault = NULL; // 禁用默認菜單
// ...
}
// CMainFrame::OnSize (動態隱藏)
void CMainFrame::OnSize(UINT nType, int cx, int cy) {
CMDIFrameWnd::OnSize(nType, cx, cy);
if (GetSafeHwnd()) {
SetMenu(NULL); // 強制移除
}
}