ObjectARX, AutoCAD. Среда программирования библиотеки C++



         

Использование COM, чтобы обратиться к AutoCAD ActiveX Автоматизация - часть 4


bIsMenuLoaded = false;

}

pPopUpMenus->Release();

Полная функция должна теперь напомнить

void

addMenuThroughCom()

{

AutoCAD::IAcadApplication *pAcad;

AutoCAD::IAcadMenuBar *pMenuBar;

AutoCAD::IAcadMenuGroups *pMenuGroups;

AutoCAD::IAcadMenuGroup *pMenuGroup;

AutoCAD::IAcadPopupMenus *pPopUpMenus;

AutoCAD::IAcadPopupMenu *pPopUpMenu;

AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;

HRESULT hr = NOERROR;

CLSID clsid;

LPUNKNOWN pUnk = NULL;

LPDISPATCH pAcadDisp = NULL;

hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);

if (SUCCEEDED(hr))

{

if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)

{

if (pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &pAcadDisp) != S_OK)

return;

pUnk->Release();

}

}

if (SUCCEEDED(pAcadDisp->QueryInterface (AutoCAD::IID_IAcadApplication,(void**)&pAcad))) {

pAcad->put_Visible(true);

}

else {

acutPrintf("\nQueryInterface trouble.");

return;

}

pAcad->get_MenuBar(&pMenuBar);

pAcad->get_MenuGroups(&pMenuGroups);

pAcad->Release();

long numberOfMenus;

pMenuBar->get_Count(&numberOfMenus);

pMenuBar->Release();

VARIANT index;

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 0;

pMenuGroups->Item(index, &pMenuGroup);

pMenuGroups->Release();

pMenuGroup->get_Menus(&pPopUpMenus);

pMenuGroup->Release();

WCHAR wstrMenuName[256];

MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,

"AsdkComAccess", -1, wstrMenuName, 256);

if (!bIsMenuLoaded) {

pPopUpMenus->Add(wstrMenuName, &pPopUpMenu);

if (pPopUpMenu != NULL) {

pPopUpMenu->put_Name(wstrMenuName);

WCHAR wstrMenuItemName[256];

MultiByteToWideChar(CP_ACP, 0,"&Add A ComCircle",

-1, wstrMenuItemName, 256);

WCHAR wstrMenuItemMacro[256];

MultiByteToWideChar(CP_ACP, 0, "AsdkComCircle ",

-1, wstrMenuItemMacro, 256);

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 0;

pPopUpMenu->AddMenuItem(index, wstrMenuItemName,




Содержание  Назад  Вперед