我在vs2008中创建的mfc工程,然后在mainframe类中的oncreate消息中添加如下代码
GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_BYPOSITION|MF_CHECKED);
GetMenu()->GetSubMenu(0)->SetDefaultItem(1,TRUE);
添加标签按钮和缺省菜单但是出错
Unhandled exception at 0x78be202c (mfc90ud.dll) in sunxin6.exe: 0xC0000005: Access violation reading location 0x00000004.
然后指向了afxwin1.inl中的
AFXWIN_INLINE CMenu* CMenu::GetSubMenu(int nPos) const
{ ASSERT(::IsMenu(m_hMenu)); return CMenu::FromHandle(::GetSubMenu(m_hMenu, nPos)); }
求高人指点啊
GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_BYPOSITION|MF_CHECKED);
GetMenu()->GetSubMenu(0)->SetDefaultItem(1,TRUE);
添加标签按钮和缺省菜单但是出错
Unhandled exception at 0x78be202c (mfc90ud.dll) in sunxin6.exe: 0xC0000005: Access violation reading location 0x00000004.
然后指向了afxwin1.inl中的
AFXWIN_INLINE CMenu* CMenu::GetSubMenu(int nPos) const
{ ASSERT(::IsMenu(m_hMenu)); return CMenu::FromHandle(::GetSubMenu(m_hMenu, nPos)); }
求高人指点啊
2、CheckMenuItem()函数的第一个参数应该是菜单子项的ID吧根据你的报错提示,问题应该是在GetMenu()没有获取到正确的菜单。你这样试试CMenu oMenu;
oMenu.LoadMenu(菜单资源ID);oMenu.GetSubMenu(0)->CheckMenuItem(子项ID,MF_BYPOSITION|MF_CHECKED);
oMenu.GetSubMenu(0)->SetDefaultItem(1,TRUE);
GetMenu()->GetSubMenu(0)->...
这个函数返回的指针都是无效的