BOOL BCMenu::RemoveMenu(UINT uiId,UINT nFlags)
{
if(MF_BYPOSITION&nFlags){
UINT uint = GetMenuState(uiId,MF_BYPOSITION);
if(uint&MF_SEPARATOR && !(uint&MF_POPUP)){
delete m_MenuList.GetAt(uiId);
m_MenuList.RemoveAt(uiId);
}
else{
BCMenu* pSubMenu = (BCMenu*) GetSubMenu(uiId);
if(NULL==pSubMenu){
UINT uiCommandId = GetMenuItemID(uiId);
for(int i=0;i<m_MenuList.GetSize(); i++){
if(m_MenuList[i]->nID==uiCommandId){
delete m_MenuList.GetAt(i);
m_MenuList.RemoveAt(i);
break;
}
}
}
else{
int numSubMenus = m_SubMenus.GetUpperBound();
for(int m = numSubMenus; m >= 0; m--){
if(m_SubMenus[m]==pSubMenu->m_hMenu){
int numAllSubMenus = m_AllSubMenus.GetUpperBound();
for(int n = numAllSubMenus; n>= 0; n--){
if(m_AllSubMenus[n]==m_SubMenus[m])m_AllSubMenus.RemoveAt(n);
}
m_SubMenus.RemoveAt(m);
}
}
int num = pSubMenu->GetMenuItemCount();
for(int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
for(i=m_MenuList.GetUpperBound();i>=0;i--){
if(m_MenuList[i]->nID==(UINT)pSubMenu->m_hMenu){
delete m_MenuList.GetAt(i);
m_MenuList.RemoveAt(i);
break;
}
}
delete pSubMenu;
}
}
}
else{
int iPosition =0;
BCMenu* pMenu = FindMenuOption(uiId,iPosition);
// bug fix RIA 14th September 2000
// failed to return correct value on call to remove menu as the item was
// removed twice. The second time its not found
// so a value of 0 was being returned
if(pMenu) return pMenu->RemoveMenu(iPosition,MF_BYPOSITION); // added return
}
return CMenu::RemoveMenu(uiId,nFlags);
}
BOOL BCMenu::DeleteMenu(UINT uiId,UINT nFlags)
{
if(MF_BYPOSITION&nFlags){
UINT uint = GetMenuState(uiId,MF_BYPOSITION);
if(uint&MF_SEPARATOR && !(uint&MF_POPUP)){
// make sure it's a separator
int menulistsize=m_MenuList.GetSize();
if(uiId<(UINT)menulistsize){
CString str=m_MenuList[uiId]->GetString();
if(str==""){
delete m_MenuList.GetAt(uiId);
m_MenuList.RemoveAt(uiId);
}
}
}
else{
BCMenu* pSubMenu = (BCMenu*) GetSubMenu(uiId);
if(NULL==pSubMenu){
UINT uiCommandId = GetMenuItemID(uiId);
for(int i=0;i<m_MenuList.GetSize(); i++){
if(m_MenuList[i]->nID==uiCommandId){
delete m_MenuList.GetAt(i);
m_MenuList.RemoveAt(i);
break;
}
}
}
else{
int numSubMenus = m_SubMenus.GetUpperBound();
for(int m = numSubMenus; m >= 0; m--){
if(m_SubMenus[m]==pSubMenu->m_hMenu){
int numAllSubMenus = m_AllSubMenus.GetUpperBound();
for(int n = numAllSubMenus; n>= 0; n--){
if(m_AllSubMenus[n]==m_SubMenus[m])m_AllSubMenus.RemoveAt(n);
}
m_SubMenus.RemoveAt(m);
}
}
int num = pSubMenu->GetMenuItemCount();
for(int i=num-1;i>=0;--i)pSubMenu->DeleteMenu(i,MF_BYPOSITION);
for(i=m_MenuList.GetUpperBound();i>=0;i--){
if(m_MenuList[i]->nID==(UINT)pSubMenu->m_hMenu){
delete m_MenuList.GetAt(i);
m_MenuList.RemoveAt(i);
break;
}
}
delete pSubMenu;
}
}
}
else{
int iPosition =0;
BCMenu* pMenu = FindMenuOption(uiId,iPosition);
if(pMenu)return pMenu->DeleteMenu(iPosition,MF_BYPOSITION);
}
return(CMenu::DeleteMenu(uiId,nFlags));
}
3 个解决方案
#1
错误显示是i未声明到底怎么改
#2
for(int i=m_MenuList.GetUpperBound();i>=0;i--)
#3
for(int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
==>
int i;放在函数开头
for( int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
将函数中所有红色的int全部去掉
或者每个for都加入int
==>
int i;放在函数开头
for( int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
将函数中所有红色的int全部去掉
或者每个for都加入int
#1
错误显示是i未声明到底怎么改
#2
for(int i=m_MenuList.GetUpperBound();i>=0;i--)
#3
for(int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
==>
int i;放在函数开头
for( int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
将函数中所有红色的int全部去掉
或者每个for都加入int
==>
int i;放在函数开头
for( int i=num-1;i>=0;--i)pSubMenu->RemoveMenu(i,MF_BYPOSITION);
将函数中所有红色的int全部去掉
或者每个for都加入int