zenggq 发表于 2005-8-27 09:08:00

请教个人定制的菜单的控制问题

<P>个人定制好的菜单,希望通过程序控制其一些子菜单项可用或不可用</P>
<P>其实以前的贴子也有了介绍,但是偶照着做好象不行,不知道哪里出了问题</P>
<P>还请哪位达人指点一二:</P>
<P>首先个人定制的菜单:</P>
<P>***Comment<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 版权所有 (C) ……大学流体工程所<BR>***MENUGROUP=fan</P>
<P>***POP1<BR>[风机(&amp;F)]<BR>[--]<BR>ID_FANCOMPUTE&nbsp;[气动计算(&amp;C)]^C^CFAN_COMPUTE<BR>[--]<BR>ID_FANBLADE&nbsp;[-&gt;叶片设计(&amp;B)]<BR>ID_FANBLADESHAPE&nbsp;[叶片造型(&amp;M)]^C^CFAN_SHAPE<BR>ID_FANBLADESHOW&nbsp;&nbsp;[&lt;-风叶显示(&amp;S)]^C^CFAN_SHOW</P>
<P>在程序中假设希望点击ID_FANCOMPUTE&nbsp;菜单后,ID_FANBLADESHOW&nbsp;&nbsp;菜单变灰</P>
<P>int fan_compute()</P>
<P>{</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acedMenuCmd("fan.ID_FANBLADESHOW&nbsp;&nbsp;= ~");</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;……</P>
<P>}</P>
<P>这样好象没反应耶,怎么回事呢?</P>
<P>另外,菜单项变灰了后再想使它可用,又该怎么办呢?</P>
<P>thx!</P>

willcan 发表于 2005-8-27 11:22:00

楼主是不是用LISP来调用自定义菜单的?能否贴出你的LISP代码给我一个参考啊?谢谢!

zenggq 发表于 2005-8-27 13:39:00

<P>呵呵不是的,就是用ARX加载菜单的</P>

willcan 发表于 2005-8-28 09:34:00

<P><A name=53595><FONT color=#000066><B>zenggq</B></FONT></A> 你好,能不能分享一下你用ARX加载菜单的代码呢?</P>
<P>我现在也需要加载我自己定义的菜单,做了一个*.mnu文件,但不知道如何在ARX里加载.</P>
<P>谢谢</P>

zenggq 发表于 2005-8-28 10:39:00

<P><BR>//加载菜单<BR>void loadMenu()<BR>{<BR>&nbsp;// 取得AutoCAD应用程序对象<BR>&nbsp;IAcadApplication *acadApp = NULL;<BR>&nbsp;LPDISPATCH pDisp = NULL;</P>
<P>&nbsp;if (!getApplication(&amp;pDisp))<BR>&nbsp;{<BR>&nbsp;&nbsp;acadApp-&gt;Release();<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;HRESULT hr = S_OK;</P>
<P>&nbsp;hr = pDisp-&gt;QueryInterface(IID_IAcadApplication, (LPVOID*)&amp;acadApp);<BR>&nbsp;if (FAILED(hr))<BR>&nbsp;{<BR>&nbsp;&nbsp;acadApp-&gt;Release();<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;// 取得所有菜单组<BR>&nbsp;IAcadMenuGroups *mnuGrps = NULL;<BR>&nbsp;long cnt = 0;<BR>&nbsp;hr = acadApp-&gt;get_MenuGroups(&amp;mnuGrps);<BR>&nbsp;if (FAILED(hr))<BR>&nbsp;{<BR>&nbsp;&nbsp;acadApp-&gt;Release();<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;acadApp-&gt;Release();<BR>&nbsp;// 菜单组个数<BR>&nbsp;mnuGrps-&gt;get_Count(&amp;cnt);<BR>&nbsp;IAcadMenuGroup *mnuGrp = NULL;<BR>&nbsp;// 循环所有菜单组,寻找菜单组,if false, load "fan.mnu".<BR>&nbsp;VARIANT vtName;<BR>&nbsp;vtName.vt = VT_I4;<BR>&nbsp;BSTR grpName;<BR>&nbsp;bool found = false;<BR>&nbsp;for (long i = 0; i &lt; cnt; i++)<BR>&nbsp;{<BR>&nbsp;&nbsp;vtName.lVal = i;<BR>&nbsp;&nbsp;hr = mnuGrps-&gt;Item(vtName, &amp;mnuGrp);<BR>&nbsp;&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;&nbsp;return;<BR>&nbsp;&nbsp;hr = mnuGrp-&gt;get_Name(&amp;grpName);<BR>&nbsp;&nbsp;CString cgrpName(grpName);<BR>&nbsp;&nbsp;if (cgrpName.CompareNoCase("fan") == 0)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;found = true;<BR>&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;mnuGrps-&gt;Release();<BR>&nbsp;if (found == false)<BR>&nbsp;{<BR>//&nbsp;&nbsp;CommandB();<BR>&nbsp;&nbsp;CString mac = "(COMMAND \"_MENULOAD\" \"fan.mnu\")"; <BR>&nbsp;&nbsp;if (acDocManager-&gt;curDocument())<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;acedPostCommand(mac);<BR>&nbsp;&nbsp;&nbsp;//如果P12不存在,则新载入的菜单加到当前菜单最后面<BR>&nbsp;&nbsp;&nbsp;acedPostCommand("(menucmd \"P11=+fan.pop1\")");&nbsp;&nbsp;<BR>&nbsp;&nbsp;}<BR>//&nbsp;&nbsp;CommandE();<BR>&nbsp;}<BR>&nbsp;mnuGrp-&gt;Release();<BR>&nbsp;return;<BR>}</P>
<P>bool getApplication(LPDISPATCH * pVal)<BR>{<BR>&nbsp;LPDISPATCH pDispatch = acedGetAcadWinApp()-&gt;GetIDispatch(TRUE);<BR>&nbsp;if (pDispatch == NULL)<BR>&nbsp;&nbsp;return false;<BR>&nbsp;*pVal = pDispatch;<BR>&nbsp;return true;<BR>}</P>
<P>&nbsp;另外loadmenu函数要加入到入口函数的case AcRx::kInitAppMsg:下面,这样AutoCAD可以自动加载它</P>
<P>再加上下面两个头文件(很大的头文件,我也不知道可不可以加小一点的头文件)</P>
<P>#include "acad15.h"<BR>#include "acad15_i.c"</P>

zenggq 发表于 2005-8-28 10:47:00

<P>前面不是有好几位大虾解答了如何让菜单变灰的方法嘛?</P>
<P>现在怎么没人出来指点一下偶的问题呢?</P>

willcan 发表于 2005-8-28 13:17:00

<A name=53681><FONT color=#000066><B>zenggq</B></FONT></A> ,谢谢你分享的代码!

zenggq 发表于 2005-8-29 20:04:00

<P>顶到有人回答为止,呵呵!</P>
<P>召唤版主大人现身!</P>

zenggq 发表于 2005-9-2 14:24:00

<P>没人回答偶</P>
<P>MY heart&nbsp;will be&nbsp;broken!</P>

skymudy 发表于 2013-2-4 20:03:10

俺也想学习一下
页: [1]
查看完整版本: 请教个人定制的菜单的控制问题