如何动态更改没有ID的MENU文本

时间:2013-11-25 07:30:55

标签: visual-studio-2008 menu mfc dialog popup

我已经尝试按照代码更改菜单文本,在命令窗口中显示正确的活动,更改菜单文本,但UI没有变化。

另外,我的菜单在对话框中,填入对话框参数的菜单字段

旧问题是

How do I change POPUP Text of Menu without ID

有人帮助我!

HMENU hMenu;
hMenu=LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU));
CMenu* pMenu = CMenu::FromHandle(hMenu);
int i, nCou = pMenu->GetMenuItemCount();
UINT uID;
CString ss;
for (i = 0; i < nCou; i++)
{   
    uID = pMenu->GetMenuItemID(i);
    if (uID == 0) // separator
    {   
        TRACE(_T("----------------------\n"));
        continue;
    }
    pMenu->GetMenuString(i, ss, MF_BYPOSITION);
    if (uID == (UINT)-1)
    {   
        TRACE(_T("Popup '%s' "), ss);
        ss += _T("-Modified");
        //pMenu->ModifyMenu(i, MF_BYPOSITION|MF_STRING|MF_ENABLED, 0, ss);
        //pMenu->ModifyMenu(i, MF_BYPOSITION|MF_STRING|MF_ENABLED, i, ss);
        //pMenu->ModifyMenu(0, MF_BYPOSITION|MF_STRING|MF_ENABLED, i, ss);
        //pMenu->ModifyMenu(0, MF_BYPOSITION|MF_STRING|MF_ENABLED, 0, ss);
        //pMenu->ModifyMenu(0, MF_BYPOSITION|MF_STRING|MF_ENABLED|MF_CHANGE, 0, ss);
        //pMenu->ModifyMenu(i, MF_BYPOSITION, 0, ss);
        pMenu->ModifyMenu(i, MF_BYPOSITION|MF_CHANGE, 0, ss);
        TRACE(_T("modified to '%s' "), ss);
    }
    else
        TRACE(_T("Item  '%s', ID=%d "), ss, uID);

    TRACE(_T("\n"));
}

1 个答案:

答案 0 :(得分:0)

我回答我的问题,更改代码

CMenu* pMenu = CMenu::FromHandle(hMenu); 

CMenu* pMenu = GetMenu();

它会起作用!非常感谢!