弱弱的问一下 我在标准MFC程序里 的CMainFrame 的OnCreate 函数后面 加上
CMenu menu;
menu.CreatePopupMenu();
GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,("X"));
编译就出错了
有人知道什么原因吗?
错误提示:
(mfc100d.dll)处有未经处理的异常:0xC0000005:读取位置0x00000004时发生访问冲突
CMenu menu;
menu.CreatePopupMenu();
GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,("X"));
编译就出错了
有人知道什么原因吗?
错误提示:
(mfc100d.dll)处有未经处理的异常:0xC0000005:读取位置0x00000004时发生访问冲突
否则函数结束后menu就没了。
menu.CreatePopupMenu();
GetMenu()->AppendMenuW(MF_POPUP,(UINT) menu.m_hMenu, _T("VC++"));
menu.AppendMenuW(MF_STRING, 111, _T("Hello"));
menu.AppendMenuW(MF_STRING, 112, _T("World"));
menu.Detach();
::AppendMenuW(this->m_hMenu,MF_POPUP,(UINT) menu.m_hMenu, _T("VC++"));
可以运行了 但是后面没有增加菜单 。
奇怪了。。
晕啊 无语了
menu.CreatePopupMenu();
GetMenu()->AppendMenu(MF_POPUP,(UINT) menu.m_hMenu, _T("VC++"));
menu.AppendMenu(MF_STRING, 1101, _T("Hello"));
menu.AppendMenu(MF_STRING, 1102, _T("World"));
//显示菜单
ClientToScreen(&point);
menu.TrackPopupMenu(TPM_RETURNCMD|TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x,point.y,this);
menu.Detach(); 我是在VS 2010中调试成功的。
// .h
// CMenu m_menu;
m_menu.CreatePopupMenu();
m_menu.AppendMenu(MF_STRING , 111, _T("Hello"));
m_menu.AppendMenu(MF_STRING , 112, _T("World"));
GetMenu()->AppendMenu(MF_POPUP,(UINT) m_menu.m_hMenu, _T("VC++"));
其他:
afx_msg void OnHello();
ON_COMMAND(111, OnHello)
void CMainFrame::OnHello()
{
// TODO: Add your command handler code here
AfxMessageBox("Hello");
}
要修改的话:
在新建工程向导。到“用户界面功能”,“命令栏(菜单/工具栏/功能区)”选用“使用经典菜单(S)”。然后,按你的代码进行编程就可以了。
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
ClientToScreen(&point);
OnContextMenu(this, point); CScrollView::OnRButtonDown(nFlags, point);
}void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
{
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_VIEW, point.x, point.y, this, TRUE);
}
GetParent()->GetMenu()->AppendMenu(MF_POPUP,(UINT)m_menu.m_hMenu,"PhoneBook");
GetParent()->DrawMenuBar();