问题描述: 

开发商有特定的需求在三维线框模式,不要让用户使用shift+鼠标中键旋转,真实模式下,用户可以使用shift+鼠标中键旋转。


步骤指引:

这里提供一些思路,可以用钩子函数来监控键盘的动作,然后加上判断当前视图是三维视图,然后就禁用该操作可以完成该方案的实现,


  1. 注册钩子函数:

    void Test_Register()
    {
    	BOOL bOK = FALSE;
    	static bool bAllowAddHook = true;
    	if (bAllowAddHook)
    	{
    		bOK = acedRegisterFilterWinMsg(ArchMsgHook);
    		bAllowAddHook = false;
    	}
    	else
    	{
    		bOK = acedRemoveFilterWinMsg(ArchMsgHook);
    		bAllowAddHook = true;
    	}
    }
  2. 钩子函数中实现:

    bool ArchMsgHook(MSG* msg)
    {
    	struct resbuf rb, rb1, rb2;
    	int rt = acedGetVar(_T("CVPORT"), &rb);
    	if (rt != RTNORM) {
    		acutPrintf(_T("\\nError !"));
    		return TRUE;
    	}
    	int vportNum = rb.resval.rint;
    
    	// Get the GS View associated with the viewport
    
    	AcGsView *pView1 = acgsGetCurrentAcGsView(vportNum/*, true*/);
    	AcGiVisualStyle visualStyle;
    
    
    	ACHAR *name = NULL;
    		AcDbObjectId currentVsId = pView1->visualStyle();
    	// if set
    	if (currentVsId != AcDbObjectId::kNull)
    	{
    		// get the owner dictionary entry, to find out the name of the visual style
    		AcDbDictionaryPointer visualStyleDict(curDoc()->database()->visualStyleDictionaryId(), AcDb::kForRead);
    		// if ok
    		if (visualStyleDict.openStatus() == Acad::eOk)
    		{
    
    			visualStyleDict->nameAt(currentVsId, name);
    
    		}
    	}
    	ACHAR *name1 = L"Wireframe";
    	if (wcscmp(name, name1) == 0)
    	{
    		if (msg->message == WM_MBUTTONDOWN) {
    			// 检查Shift键是否被按下
    			if (GetKeyState(VK_SHIFT) & 0x8000) {
    
    				// Shift + 鼠标中键被按下
    				// 在这里处理你的逻辑
    				//MessageBox(NULL, L"Shift + 鼠标中键被按下!", L"提示", MB_OK);
    				return TRUE;
    			}
    		}
    	}
    
    	return FALSE;
    }
  3. 钩子函数中如果命中条件返回True则终止执行任务。
  4. 扩展:可以根据自己需求来修改监控鼠标和键盘操作,并添加其他条件。
英文空间链接

★★中望CAD 如何让用户三维线框模式禁止shift+鼠标中键旋转视图?https://confluence.zwcad.com/pages/viewpage.action?pageId=295504331
  • No labels