最近用到了系统菜单,按照网上的说法是如下面实现的:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CWnd* pMain = AfxGetMainWnd();
// The main window _can_ be NULL, so this code
// doesn't ASSERT and actually tests.
if (pMain != NULL)
{
// Get the main window's menu
CMenu* pMenu = GetSystemMenu(FALSE);
// If there is a menu and it has items, we'll
// delete the first one.
if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
{
pMenu->DeleteMenu(SC_MOVE, MF_BYCOMMAND);
// force a redraw of the menu bar
pMain->DrawMenuBar();
}
// No need to delete pMenu because it is an MFC
// temporary
}
return 0;
}
但是我在在单文档程序和对话框中的onCreate函数中加入上面代码删除的系统菜单项依然显示,只是菜单项没任何功能响应!我在对话框的OnInitDialog()中实现这段代码功能是正确的!我在单文档程序的中实现:
CWnd* pMain = AfxGetMainWnd();
if (pMain != NULL)
{
// Get the main window's menu
CMenu* pMenu = GetSystemMenu(FALSE);
// If there is a menu and it has items, we'll
// delete the first one.
if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
{
pMenu->DeleteMenu(SC_MOVE, MF_BYCOMMAND);
pMenu->DeleteMenu(SC_CLOSE, MF_BYCOMMAND);
// force a redraw of the menu bar
//pMain->DrawMenuBar();
}
pMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, pMain, 0);
}
我想实现这个功能很简单,单文档程序在OnContextMenu中实现不是最好的方法!在其他函数中应该可以稍微简单的实现!