删除系统菜单的方法

     最近用到了系统菜单,按照网上的说法是如下面实现的:

 

    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中实现不是最好的方法!在其他函数中应该可以稍微简单的实现!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值