加载/卸载指定的菜单
问题:
I want to load a submenu when my ObjectARX application is loaded and remove it when it is unloaded. The following code does not work:
//
acedCommand (RTSTR, _T("_.CUILOAD"), RTSTR,_T("C:/TEST.CUI"), RTNONE) ;
acedMenuCmd (_T("P7=+TEST.POP1")) ;
//
acedCommand (RTSTR, _T("_.CUIUNLOAD"), RTSTR, _T("TEST"), RTNONE) ;
解决方案:
Using acedCommand() within an acrxEntryPoint() or within a reactor is problematic. To get around this limitation, it is possible to use the undocumented function ads_queueexpr(). The following code demonstrates how you would use it to load and unload a menu specific to your application.
The swprintf() expression in an initApp() function prepares a string that will both load the menu (using CUILOAD). Call this from On_kInitAppMsg. To add the POP1 menu in at the POP7 location, it is better to delegate this into the associated .MNL file.
**** Hidden Message *****
The presence of the ARX application associated to the .MNU file loaded is tested
in the MNL file. If it is not present, unload the menu. The problem is that
during the AcRx::kUnloadAppMsg message, an AutoLISP expression is queued.
Unfortunately, this expression is evaluated only when AutoCAD will be next in
ready state. During a quit sequence AutoCAD will never be in ready state again,
so the expression will never be evaluated. The solution to that problem is to
delegate the menu unload operation to the next time AutoCAD starts. To do this,
associate an .MNL file to our menu, which checks the presence of the ARX
application. If it is not present, then unload the partial loaded menu as
demonstrated here.
;; Associated .mnl file, Note: If S::STARTUP is included in an MNL file, it is called when you enter a new drawing or open an existing drawing
(defun-q MyMenuFunc ()
(if (/= (member "myapp.arx" (arx)) nil) ;notice the name of the arx is all lower case for this if statement
(menucmd "p7=+TEST.POP1") ;; if ARX app present, push POP1 into position 7
(command "_.menuunload" "TEST") ;; else unload the menu
)
(princ)
)
(if S::STARTUP
(if (equal (type S::STARTUP) 'LIST)
(setq S::STARTUP (append S::STARTUP MyMenuFunc))
)
(setq S::STARTUP MyMenuFunc)
)
啥也不说了,感谢楼主分享哇! 啥也不说了,感谢楼主分享哇! 确实是难得好帖啊,顶先 回复学习
飘过学习.........
确实是难得好帖啊,顶先 Thanks for sharing! 谢谢分享,学习arx的菜单加载方法~~ 学习一下
看看,学习下菜单 11111111111111111111111 回复看看帖子,学习学些。。。。 我就想知道怎么卸载菜单 回复学习学习,谢谢
页:
[1]
2