Немного измененный пример polymnu:
IAcadMenuGroup *mnuGrp=NULL;
...
static void cre ateMenus(IAcadMenuGroup *mnuGrp)
{
mnuGrp = NULL;
if (!getAcadMenuGroup(&mnuGrp))
{
return ;
}
//now get all the popup menus
IAcadPopupMenus *mnus = NULL;
HRESULT hr = S_OK;
hr = mnuGrp->get_Menus(&mnus);
long cnt = 0l;
hr = mnus->get_Count(&cnt);
mnuGrp->Release();
//now get Tools menu
IAcadPopupMenu *toolsMenu = NULL;
BSTR tempName = _T("My menu");
VARIANT vtName;
bool found = false;
for (long i=0; i < 02; i++)
{
vtName.vt = VT_I4;
vtName.lVal = i;
hr = mnus->Item(vtName, &toolsMenu);
if (FAILED(hr))
{
acutPrintf(_T("!!!!@##$!!!"));
return ;
}
toolsMenu->put_Name(tempName);
hr = toolsMenu->get_NameNoMnemonic(&tempName);
CString mnuName(tempName);
if(mnuName.CompareNoCase(_T("My menu"))==0)
{
found = true;
break;
}
//acedAlert(_T("!!!"));
}
mnus->Release();
if (!found)
{
acedAlert(_T("Could not found tools menu\n"));
return;
}
hr = toolsMenu->get_Count(&cnt);
VARIANT vtIndex;
vtIndex.vt = VT_I4;
vtIndex.lVal = cnt + 1;
toolsMenu->InsertInMenuBar(vtIndex);
IAcadPopupMenuItem *item1 = NULL;
hr = toolsMenu->AddSeparator(vtIndex, &item1);
item1->Release();
vtIndex.lVal = cnt + 2;
IAcadPopupMenu *polyMnu = NULL;
hr = toolsMenu->AddSubMenu(vtIndex, L"My commands", &polyMnu);
if(FAILED(hr))
return;
toolsMenu->Release();
IAcadPopupMenuItem *polycmds = NULL;
vtIndex.lVal = 0;
hr = toolsMenu->AddMenuItem(vtIndex, L"Command1", _T("command1 "), &polycmds);
vtIndex.lVal = 1;
hr = toolsMenu->AddMenuItem(vtIndex, L"Command2", L"command1 ", &polycmds);
vtIndex.lVal = 2;
hr = toolsMenu->AddMenuItem(vtIndex, L"Command3", L"command1 ", &polycmds);
vtIndex.lVal = 3;
hr = toolsMenu->AddMenuItem(vtIndex, L"Command4", L"command1 ", &polycmds);
vtIndex.lVal = 0;
hr = polyMnu->AddMenuItem(vtIndex, L"Command1", L"command1 ", &polycmds);
vtIndex.lVal = 1;
hr = polyMnu->AddMenuItem(vtIndex, L"Command2", L"command1 ", &polycmds);
vtIndex.lVal = 2;
hr = polyMnu->AddMenuItem(vtIndex, L"Command3", L"command1 ", &polycmds);
vtIndex.lVal = 3;
hr = polyMnu->AddMenuItem(vtIndex, L"Command4", L"command1 ", &polycmds);
vtIndex.lVal = 4;
// polycmds->Release();
polyMnu->Release();
return;
}