ObkectARX为cad添加新的菜单
<p>请教各位怎样使用objectARX为cad添加新的菜单和菜单项。</p><p>相关的代码怎么写啊</p><p>谢谢!</p><p></p> <pre class="prog_in_0">看帮助Com and ActiveX Automation中有</pre><pre class="prog_in_0">void addMenuThroughCom()</pre><pre class="prog_in_0">{</pre><pre class="prog_in_0"> AutoCAD::IAcadApplication *pAcad;</pre><pre class="prog_in_0"> AutoCAD::IAcadMenuBar *pMenuBar;</pre><pre class="prog_in_0"> AutoCAD::IAcadMenuGroups *pMenuGroups;</pre><pre class="prog_in_0"> AutoCAD::IAcadMenuGroup *pMenuGroup;</pre><pre class="prog_in_0"> AutoCAD::IAcadPopupMenus *pPopUpMenus;</pre><pre class="prog_in_0"> AutoCAD::IAcadPopupMenu *pPopUpMenu;</pre><pre class="prog_in_0"> AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;</pre><pre class="prog_in_0"> HRESULT hr = NOERROR;</pre><pre class="prog_in_0"> CLSID clsid;</pre><pre class="prog_in_0"> LPUNKNOWN pUnk = NULL;</pre><pre class="prog_in_0"> LPDISPATCH pAcadDisp = NULL; </pre><pre class="prog_in_0"></pre><pre class="prog_in_0"> hr = ::CLSIDFromProgID(L"AutoCAD.Application",</pre><pre class="prog_in_0"> &clsid);</pre><pre class="prog_in_0"> if (FAILED(hr))</pre><pre class="prog_in_0"> return;</pre><pre class="prog_in_0"> if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK)</pre><pre class="prog_in_0"> return;</pre><pre class="prog_in_0"></pre><pre class="prog_in_0"> hr = pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &pAcadDisp);</pre><pre class="prog_in_0"> pUnk->Release();</pre><pre class="prog_in_0"> if (FAILED(hr))</pre><pre class="prog_in_0"> return;</pre><pre class="prog_in_0"></pre><pre class="prog_in_0"> hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication, (void**)&pAcad);</pre><pre class="prog_in_0"> pAcadDisp->Release();</pre><pre class="prog_in_0"> if (FAILED(hr))</pre><pre class="prog_in_0"> return;</pre><pre class="prog_in_0"></pre><pre class="prog_in_0"> pAcad->put_Visible(true);</pre><pre class="prog_in_0"> pAcad->get_MenuBar(&pMenuBar);</pre><pre class="prog_in_0"> pAcad->get_MenuGroups(&pMenuGroups);</pre><pre class="prog_in_0"> pAcad->Release();</pre><pre class="prog_in_0"> long numberOfMenus;</pre><pre class="prog_in_0"> pMenuBar->get_Count(&numberOfMenus);</pre><pre class="prog_in_0"> pMenuBar->Release();</pre><pre class="prog_in_0"> VARIANT index;</pre><pre class="prog_in_0"> VariantInit(&index);</pre><pre class="prog_in_0"> V_VT(&index) = VT_I4;</pre><pre class="prog_in_0"> V_I4(&index) = 0;</pre><pre class="prog_in_0"> pMenuGroups->Item(index, &pMenuGroup);</pre><pre class="prog_in_0"> pMenuGroups->Release();</pre><pre class="prog_in_0"></pre><pre class="prog_in_0"> pMenuGroup->get_Menus(&pPopUpMenus);</pre><pre class="prog_in_0"> pMenuGroup->Release();</pre><pre class="prog_in_0"> WCHAR wstrMenuName;</pre><pre class="prog_in_0"> MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, </pre><pre class="prog_in_0"> "AsdkComAccess", -1, wstrMenuName, 256); </pre><pre class="prog_in_0"> if (!bIsMenuLoaded) {</pre><pre class="prog_in_0"> pPopUpMenus->Add(wstrMenuName, &pPopUpMenu);</pre><pre class="prog_in_0"> if (pPopUpMenu != NULL) {</pre><pre class="prog_in_0"> pPopUpMenu->put_Name(wstrMenuName);</pre><pre class="prog_in_0"> WCHAR wstrMenuItemName;</pre><pre class="prog_in_0"> MultiByteToWideChar(CP_ACP, 0,"&Add A ComCircle",</pre><pre class="prog_in_0"> -1, wstrMenuItemName, 256); </pre><pre class="prog_in_0"> WCHAR wstrMenuItemMacro;</pre><pre class="prog_in_0"> MultiByteToWideChar(CP_ACP, 0, "AsdkComCircle ",</pre><pre class="prog_in_0"> -1, wstrMenuItemMacro, 256); </pre><pre class="prog_in_0"> VariantInit(&index);</pre><pre class="prog_in_0"> V_VT(&index) = VT_I4;</pre><pre class="prog_in_0"> V_I4(&index) = 0;</pre><pre class="prog_in_0"> pPopUpMenu->AddMenuItem(index, wstrMenuItemName,</pre><pre class="prog_in_0"> wstrMenuItemMacro, &pPopUpMenuItem);</pre><pre class="prog_in_0"> VariantInit(&index);</pre><pre class="prog_in_0"> V_VT(&index) = VT_I4;</pre><pre class="prog_in_0"> V_I4(&index) = 1;</pre><pre class="prog_in_0"> pPopUpMenu->AddSeparator(index, </pre><pre class="prog_in_0"> &pPopUpMenuItem);</pre><pre class="prog_in_0"> MultiByteToWideChar(CP_ACP, 0,</pre><pre class="prog_in_0"> "Auto&LISP Example", -1, </pre><pre class="prog_in_0"> wstrMenuItemName, 256); </pre><pre class="prog_in_0"> MultiByteToWideChar(CP_ACP, 0,</pre><pre class="prog_in_0"> "(prin1 \"Hello\") ", -1, </pre><pre class="prog_in_0"> wstrMenuItemMacro, 256); </pre><pre class="prog_in_0"> VariantInit(&index);</pre><pre class="prog_in_0"> V_VT(&index) = VT_I4;</pre><pre class="prog_in_0"> V_I4(&index) = 2;</pre><pre class="prog_in_0"> pPopUpMenu->AddMenuItem(index, wstrMenuItemName,</pre><pre class="prog_in_0"> wstrMenuItemMacro, &pPopUpMenuItem);</pre><pre class="prog_in_0"> VariantInit(&index);</pre><pre class="prog_in_0"> V_VT(&index) = VT_I4;</pre><pre class="prog_in_0"> V_I4(&index) = numberOfMenus - 2;;</pre><pre class="prog_in_0"> pPopUpMenu->InsertInMenuBar(index);</pre><pre class="prog_in_0"> pPopUpMenu->Release();</pre><pre class="prog_in_0"> pPopUpMenuItem->Release();</pre><pre class="prog_in_0"></pre><pre class="prog_in_0"> bIsMenuLoaded = true;</pre><pre class="prog_in_0"> } else {</pre><pre class="prog_in_0"> acutPrintf("\nMenu not created.");</pre><pre class="prog_in_0"> }</pre><pre class="prog_in_0"> } else {</pre><pre class="prog_in_0"> VariantInit(&index);</pre><pre class="prog_in_0"> V_VT(&index) = VT_BSTR;</pre><pre class="prog_in_0"> V_BSTR(&index) = wstrMenuName;</pre><pre class="prog_in_0"> pPopUpMenus->RemoveMenuFromMenuBar(index);</pre><pre class="prog_in_0"> VariantClear(&index);</pre><pre class="prog_in_0"> bIsMenuLoaded = false;</pre><pre class="prog_in_0"> }</pre><pre class="prog_in_0"> pPopUpMenus->Release();</pre><pre class="prog_in_0">}</pre>
页:
[1]