梦想控件中鼠标事件的响应
<div><strong><a name="_Toc272417239"><font size="2"><span><font face="Verdana">第 1 章</font><span> </span><font face="Verdana">VC</font></font></span></a><span><font size="2">语言调用</font></span></strong></div><div><strong><a name="_Toc274745313"><font size="2"><font face="Verdana">1.1</font><span> </span><font face="Verdana">CMxDrawFilterWinMsgObject</font></font></a><font size="2">类</font></strong></div>
<div> </div>
<div> 控件中的窗口消息处理反应器基类,用户从该类继承自己的基类,并重载相应的虚函数,在虚函数里实现对事件的处理代码,然后把基类的实例对象指针调用函数MxDraw::RegisterFilterWinMsg注册到系统中,调用MxDraw::UnRegisterFilterWinMsg反注消。</div>
<div> </div>
<div><strong><font color="#666699"><font size="1"><font face="Times New="New"Roman">VC</font>接口:</font></font></strong></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewLButtonDown</font></strong>(<u>UINT</u> nFlags,<u>McGePoint2d</u> point);</div>
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewLButtonUp</font></strong>(<u>UINT</u> nFlags,<u>McGePoint2d</u> point);</div>
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewMouseMove</font></strong>(<u>UINT</u> nFlags,<u>McGePoint2d</u> point);</div>
<div align="left"> </div>
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewMButtonDown</font></strong>(<u>UINT</u> nFlags,<u>McGePoint2d</u> point);</div>
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewMButtonUp(</font></strong><u>UINT</u> nFlags,<u>McGePoint2d</u> point);</div>
<div> virtual <font face="Times New="New"Roman">LRESULT<strong> OnViewMouseWheel</strong></font>(<u>UINT</u> nFlags, <u>short</u> zDelta, <u>CPoint</u> pt);</div>
<div align="left"> </div>
<div> virtual <font face="Times New="New"Roman">LRESULT<strong> OnViewMButtonDblClk</strong></font>(<u>UINT</u> nFlags, <u>McGePoint2d</u> point);</div>
<div align="left"> </div>
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewLButtonDblClk</font></strong>(<u>UINT</u> nFlags, <u>McGePoint2d</u> point);</div>
<div align="left"> </div>
<div> virtual <font face="Times New="New"Roman">LRESULT</font> <strong><font face="Times New="New"Roman">OnViewRButtonDown(</font></strong><u>UINT</u> nFlags,<u>McGePoint2d</u> point);</div>
<div><strong> virtual </strong><font face="Times New="New"Roman">LRESULT</font><font face="Times New="New"Roman">OnViewRButtonUp</font><strong>(</strong><u>UINT</u><strong> nFlags,</strong><u>McGePoint2d</u><strong> point);</strong></div></blockquote>
<div><strong><font color="#666699" size="1">参数:</font></strong></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> nFlags<font face="Times New="New"Roman"> </font>事件标志,与<font face="Times New="New"Roman">Windows</font>的鼠标事件中的<font face="Times New="New"Roman">nFlags</font>是同一个值</div>
<div><font face="Times New="New"Roman"> point 是鼠标事件发生屏幕位置,单位窗口视区坐标</font></div>
<div> 返回值<font face="Times New="New"Roman"> </font>返回为<font face="Times New="New"Roman">0</font>鼠标事件会继续传递,非<font face="Times New="New"Roman">0</font>事件不会继续传递。</div></blockquote>
<div> </div>
<div><strong><font color="#666699"><font size="1"><font face="Times New="New"Roman">VC</font>调用参考例程:</font></font></strong></div>
<div> 参考例程在控件安装目录下<font face="Times New="New"Roman">sample\Edit\Edit.sln</font>中,例程中,响应了鼠标左键双击事件,在双事件里,找到鼠标双击位置下的实体,得到实体信息并提示。</div>
<div>代码如下:</div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> </div>
<div><u><font color="#c0504d">在对话框初化函数中,创建事件反应器,并注册到系统中</font></u></div>
<div align="left">m_pWndMsg = new CWinMsg(m_hDrawOcx);</div>
<div align="left"> MxDraw::RegisterFilterWinMsg(m_hDrawOcx,m_pWndMsg);</div>
<div align="left"> </div>
<div><u><font color="#c0504d">在对话框退出时,反注册</font></u></div>
<div align="left">void CTestDlg::OnDestroy()</div>
<div align="left">{</div>
<div align="left"> <font face="Times New="New"Roman">…</font>.</div>
<div align="left"> <strong>MxDraw::UnRegisterFilterWinMsg(m_hDrawOcx,m_pWndMsg);</strong></div>
<div align="left"> <font face="Times New="New"Roman">…</font>..</div>
<div align="left">}</div>
<div align="left"> </div>
<div><u><font color="#c0504d">重载鼠标双击事件函数,并加上处理代码</font></u></div>
<div align="left"><strong>LRESULT</strong><strong> CWinMsg::OnViewLButtonDblClk(UINT nFlags, McGePoint2d point)</strong></div>
<div align="left">{</div>
<div align="left"> </div>
<div align="left"> CPoint ptView((int)point.x,(int)point.y);</div>
<div><font color="#008000"><font face="System"> // </font>把视区会标变成文档坐标</font></div>
<div align="left"> AcGePoint3d pt = MxDraw::ViewToDocCoord(m_hOcx,ptView);</div>
<div align="left"> </div>
<div align="left"> double dWidth = 1.0;</div>
<div align="left"> double dHeight = 1.0;</div>
<div align="left"> </div>
<div><font color="#008000"><font face="System"> // </font>得到光标拾取框的大小</font></div>
<div align="left"> int iWidth = 6;</div>
<div align="left"> MxDraw::GetCursorPickRect(m_hOcx,iWidth);</div>
<div align="left"> </div>
<div align="left"> dWidth = MxDraw::ViewLongToDocCoord(m_hOcx,iWidth);</div>
<div align="left"> dHeight = dWidth;</div>
<div align="left"> </div>
<div><font color="#008000"><font face="System"> // </font>在一点,和给定的范围内搜索实体</font></div>
<div align="left"> AcDbObjectIdArray aryId;</div>
<div align="left"> MxTools::FindEntAtPoint(pt,NULL,dWidth / 2.0,aryId);</div>
<div align="left"> </div>
<div align="left"> if(aryId.length() > 0)</div>
<div align="left"> {</div>
<div><font color="#008000"><font face="System"> // </font>找到实体后,读方式打开实体,读取信息</font></div>
<div align="left"> AcDbObjectId entId = aryId;</div>
<div align="left"> AcDbObjectPointer<AcDbEntity> spEnt(entId,AcDb::kForRead);</div>
<div align="left"> if(spEnt.openStatus() == Acad::eOk)</div>
<div align="left"> {</div>
<div><font color="#008000"><font face="System"> // </font>得到实的类名<font face="System">.</font></font></div>
<div align="left"> CString sClassName = spEnt->isA()->name();</div>
<div align="left"> </div>
<div><font color="#008000"><font face="System"> // </font>得到实体名柄</font></div>
<div align="left"> AcDbHandle handle;</div>
<div align="left"> spEnt->getAcDbHandle(handle);</div>
<div align="left"> TCHAR szHandle;</div>
<div align="left"> handle.getIntoAsciiBuffer(szHandle);</div>
<div><font color="#008000"><font face="System"> // </font>得到实体层名</font></div>
<div align="left"> CString sLayerName;</div>
<div align="left"> {</div>
<div align="left"> AcDbObjectPointer<AcDbLayerTableRecord> spLayerTableRec(spEnt->layerId(),AcDb::kForRead);</div>
<div align="left"> if(spLayerTableRec.openStatus() == Acad::eOk)</div>
<div align="left"> {</div>
<div align="left"> LPCTSTR pszLayerName = NULL;</div>
<div align="left"> spLayerTableRec->getName(pszLayerName);</div>
<div align="left"> sLayerName = pszLayerName;</div>
<div align="left"> }</div>
<div align="left"> }</div>
<div align="left"> </div>
<div align="left"> CString sT;</div>
<div align="left"> sT.Format(_T("类名:%s,层名:%s,名柄:%s"),sClassName,sLayerName,szHandle);</div>
<div align="left"> </div>
<div align="left"> AfxMessageBox(sT);</div>
<div align="left"> </div>
<div><font color="#008000"><font face="System"> // 取消框选命令。</font></font></div>
<div align="left"> MxDraw::SendStringToExecute(m_hOcx,_T(""));</div>
<div><font face="System"> /<font color="#008000">/ </font></font><font color="#008000">返回<font face="System">1 </font>表示鼠标事件不在住下传递。</font></div>
<div align="left"> return 1;</div>
<div align="left"> }</div>
<div align="left"> }</div>
<div align="left"> </div>
<div align="left"> return 0;</div>
<div align="left">}</div>
<div align="left"> </div>
<div align="left"> </div>
<div align="left"> </div></blockquote>
<div><strong><a name="_Toc272416352"><span><font size="2"><span><font face="Verdana">第 2 章</font><span> </span><font face="Verdana">COM</font></font></span></span></a><span><span><font size="2">接口</font></span></span></strong></div>
<div> 在<font face="Times New="New"Roman">MxDrawX.ocx</font>中,响应鼠标事件<strong>MouseEventEvent</strong>来实现。</div>
<div> </div>
<div><strong><a name="_Toc274745315"><font size="2"><font face="Verdana">2.1</font><span> </span><font face="Verdana">MouseEventEvent</font></font></a></strong></div>
<div> </div>
<div><strong><font color="#666699" size="1">接口定义:</font></strong></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div align="left">public <strong>MouseEventEvent</strong>(<strong><u>int</u></strong> <em>lType</em><strong>, </strong><strong><u>double</u></strong> <em>dX</em><strong>, </strong><strong><u>double</u></strong> <em>dY</em><strong>, </strong><strong><u>int</u></strong> <em>lRet</em>)</div>
<div> <strong><u>AxMxDrawXLib</u></strong>.<strong><u>_DMxDrawXEvents_MouseEventEvent</u></strong> 的成员</div></blockquote>
<div><strong><font color="#666699" size="1">参数:</font></strong></div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div>lType<font face="Times New="New"Roman"> 事件类型,详细函义如下:</font></div>
<div><font face="Times New="New"Roman"> 1</font>鼠标移动,<font face="Times New="New"Roman">2</font>是鼠标左键按下,</div>
<div><font face="Times New="New"Roman"> 3</font>是鼠标右键按下,<font face="Times New="New"Roman">4</font>是鼠标左键双击</div>
<div><font face="Times New="New"Roman"> 5</font>是鼠标左键释放</div>
<div><font face="Times New="New"Roman"> 6</font>是鼠标右键释放</div>
<div> </div>
<div><font face="Times New="New"Roman"> 7</font>是鼠标中键按下</div>
<div><font face="Times New="New"Roman"> 8</font>是鼠标中键释放</div>
<div><font face="Times New="New"Roman"> 9</font>是鼠标中键双击</div>
<div> </div>
<div> </div>
<div><font face="Times New="New"Roman">dX</font>,<font face="Times New="New"Roman">dY 是鼠标事件发生屏幕位置,单位文档坐标</font></div>
<div><font face="Times New="New"Roman">lRet 返回值,为<font face="Times New="New"Roman">0</font>鼠标事件会继续传递,非<font face="Times New="New"Roman">0</font>事件不会继续传递。</font></div>
<div> </div></blockquote>
<div><strong><font color="#666699" size="1">调用参考例程:</font></strong></div>
<div> 参考例程在控件安装目录下<font face="Times New="New"Roman">sample\ CSharp\ CSharp.sln</font>中,例程中,响应了鼠标左键双击事件,在双事件里,找到鼠标双击位置下的实体,得到实体信息并提示。</div>
<div>代码如下:</div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div> </div>
<div align="left">private void axMxDrawX1_MouseEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_MouseEventEvent e)</div>
<div align="left"> {</div>
<div align="left"> if(e.lType == 4)</div>
<div align="left"> {</div>
<div><font color="#008000"><font face="System"> // 鼠标左键双击<font face="System">.</font></font></font></div>
<div><font color="#008000"><font face="System"> // 构建选择集,找到鼠标左建双击下的实体。</font></font></div>
<div align="left"> MxDrawSelectionSet ss = new MxDrawSelectionSet();</div>
<div align="left"> MxDrawResbuf filter = new MxDrawResbuf();</div>
<div align="left"> </div>
<div align="left"> MxDrawPoint point = new MxDrawPoint();</div>
<div align="left"> point.x = e.dX;</div>
<div align="left"> point.y = e.dY;</div>
<div align="left"> </div>
<div align="left"> ss.SelectAtPoint2(point,filter);</div>
<div align="left"> </div>
<div align="left"> if(ss.Count > 0)</div>
<div align="left"> {</div>
<div align="left"> MxDrawEntity ent = ss.Item(0);</div>
<div align="left"> MessageBox.Show("点击了" + ent.ObjectName + "对象");</div>
<div align="left"> </div>
<div align="left"> /*</div>
<div align="left"> if (ent is MxDrawLine)</div>
<div align="left"> {</div>
<div align="left"> MxDrawLine line = (MxDrawLine)ent;</div>
<div align="left"> }</div>
<div align="left"> */</div>
<div align="left"> }</div>
<div align="left"> e.lRet = 1;</div>
<div><font color="#008000"><font face="System"> // </font>取消后面的命令。</font></div>
<div align="left"> axMxDrawX1.SendStringToExecute("");</div>
<div align="left"> }</div>
<div> }</div></blockquote> 在ARX中也可以使用钩子来响应这些事件 怎么用法?没看明白
请问这些源代码可以怎么找到? 东西在哪里? 去我们网上下载,www.mxdraw.com
页:
[1]