laoxie_198 发表于 2008-3-29 12:30:00

[求助]怎样在cad中获取鼠标右击事件?

<p></p><p>下面是我用关键字的有点问题,请大家帮我看看怎么回事。我想在注记的时候通过鼠标右键来结束程序,该怎么弄呢?</p><p>ption Explicit</p><p><br/>Private Const VK_ESCAPE = &amp;H1B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 代表Esc键<br/>Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer<br/>Sub ll()<br/>Dim cn As New ADODB.Connection<br/>Dim gdp As New ADODB.Recordset<br/>Dim sqllj As String, jfh As String<br/>Dim maxzdh As Integer, zdh As Integer '最大宗地号、宗地号<br/>Dim zjpoint(0 To 2) As Double&nbsp; '注记点坐标<br/>Dim textobj As AcadText<br/>Dim tc As AcadLayer<br/>Dim msg As String<br/>msg$ = "请输入街坊号:"<br/>i: jfh = Trim(InputBox(msg$, "数据输入", " 320506432002"))<br/>If jfh = "" Then<br/>&nbsp; MsgBox "街坊号输入有误,请重新输入"<br/>&nbsp; GoTo i<br/>&nbsp;End If<br/>sqllj = "provider=sqloledb.1;password= ;persist security info=true;user id=sa;initial catalog=wzdb ;data source=hbxx"<br/>cn.Open sqllj<br/>gdp.Open "select zd=max(description) from gdp where pid in (select lpid from gdlp where isvirtual =0) and eoid in (select eoid from gdeo where description='" &amp; jfh &amp; "')", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not gdp.EOF Then<br/>&nbsp;maxzdh = gdp.Fields("zd")<br/>End If<br/>gdp.Close<br/>cn.Close<br/>Dim returnPnt As Variant<br/>Dim ptPrevious As Variant<br/>Dim strKeyWords As String<br/>&nbsp;&nbsp;&nbsp; strKeyWords = "W E O"<br/>&nbsp;&nbsp;&nbsp; Dim objPline As AcadLWPolyline<br/>NEXTPOINT:<br/>&nbsp;&nbsp;&nbsp; ' 设置关键字<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.InitializeUserInput 128, strKeyWords<br/>&nbsp;&nbsp;&nbsp; BeginShortcutMenuDefault<br/>&nbsp;&nbsp;&nbsp; returnPnt = ThisDrawing.Utility.GetPoint(, "请点取宗地号注记位置:&lt;结束(e)&gt;: ")<br/>&nbsp;&nbsp;&nbsp; If Err Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 在错误处理中判断用户输入的关键字<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If StrComp(Err.Description, "用户输入的是关键字", 1) = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim strInput As String<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strInput = ThisDrawing.Utility.GetInput<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 根据输入的关键字进行相应的处理<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If StrComp(strInput, "e", vbTextCompare) = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'GoTo NEXTPOINT<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GoTo NEXTPOINT<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'ElseIf StrComp(Err.Description, "自动化 (Automation) 错误", vbTextCompare) = 0 Then<br/>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ElseIf Err.Number = -2147352567 Then<br/>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 判断用户是否按下了Esc键<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If CheckKey(VK_ESCAPE) = True Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zjpoint(0) = returnPnt(0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zjpoint(1) = returnPnt(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zjpoint(2) = returnPnt(2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zdh = maxzdh + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set textobj = ThisDrawing.ModelSpace.AddText(zdh, zjpoint, 2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textobj.Update<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxzdh = maxzdh + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GoTo NEXTPOINT<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Return a point using a prompt<br/>'returnPnt = ThisDrawing.Utility.GetPoint(, "请点取宗地号注记位置: ")</p><p><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Application.ZoomAll<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>End Sub<br/><br/>Private Function CheckKey(lngKey As Long) As Boolean<br/>&nbsp;&nbsp;&nbsp; If GetAsyncKeyState(lngKey) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CheckKey = True<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CheckKey = False<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Function<br/></p>
页: [1]
查看完整版本: [求助]怎样在cad中获取鼠标右击事件?