马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 Lispboy 于 2018-1-23 00:28 编辑
Issue
Is there a way to prevent AutoCAD from starting a selection box when a command
is not active in ObjectARX?
问题:ObjectARX中,有没有办法在AutoCAD没有命令激活时候,阻止启动选择框?
Solution
The problem in the context where there is not an active command is that AutoCAD
can do a box selection operation (this is what should be avoided) or a pick set
selection if an entity is under the mouse pointer. At the time you see the
message, AutoCAD has not yet "seen" the message, therefore, you need to
determine in which context you are. The solution to that problem is the
following:
If the AutoCAD CMDACTIVE variable is equal to 0, then post the WM_LBUTTONDOWN
message again to AutoCAD using the same parameters (but be carefull about the
endless loop).
This method does not "break" anything in AutoCAD and the box selection is
disabled and at the other corner, AutoCAD prompts are automatically fed by the
second WM_LBUTTONDOWN message.
解答:在AUTOCAD命令未激活情况下,单选实体允许,但窗口选择禁止,这个时候,你可以看到消息,而不让AUTOCAD看见,因此解决方法如下:
如果系统变量CMDACTIVE=0,你继续用相同的消息参数POST给AUTOCAD一个鼠标左键按下的消息,让AUTOCAD以为它已经拉出窗口鼠标单击结束了。需要注意的是要避免无限循环。
解决的ARX代码如下:
- void watch (const MSG *pMsg) {
- static BOOL bStopLoop =FALSE ;
- struct resbuf result ;
- if ( acedGetAcadDwgView ()->GetSafeHwnd () == pMsg->hwnd && pMsg->message == WM_LBUTTONDOWN ) {
- ads_getvar (L"CMDACTIVE", &result) ;
- if ( result.resval.rint == 0 ) {
- if ( !bStopLoop ) {
- acedGetAcadDwgView ()->PostMessage (WM_LBUTTONDOWN, pMsg->wParam, pMsg->lParam) ;
- bStopLoop =TRUE ;
- } else {
- bStopLoop =FALSE ;
- }
- }
- }
- }
Use 'acedRegisterWatchWinMsg (watch);' to register the callback function in
AutoCAD and 'acedRemoveWatchWinMsg (watch);' to unregister it.
好了,上面是ARX的解决方案,下面我们用LISP实现它。
- (defun c:tt ()
- (defun _hook (hwnd msg wparam lparam ti pos)
- (cond
- ((= msg WM_LBUTTONDOWN);监视鼠标左键按下消息
- (setq result (getvar "cmdactive"));;cmdactive=0时候,禁止拉窗口
- (if (= result 0)
- (progn
- (if (not bStopLoop)
- (progn
- (alert "\n别按啦,禁止你了!!!")
- (xdrx_hook_postmessage WM_LBUTTONDOWN wparam lparam);;post给AUTOCAD第二个鼠标左键按下的消息
- (setq bStopLoop t);;避免无限循环
- )
- (progn (setq bStopLoop nil))
- )
- )
- )
- )
- )
- )
- (xdrx_begin)
- (xd::hook:register "_hook" t "禁止非命令状态窗选hook")
- (xdrx_end)
- (princ)
- )
|