- 积分
- 73549
- 明经币
- 个
- 注册时间
- 2001-6-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-4-18 20:42:00
|
显示全部楼层
完整的版本如下(利用了API增加对ESC键的判断)
本帖最后由 mccad 于 2003-4-18 20:42:53 编辑
以下为程序部分:
- On Error GoTo Err_Control
- Dim Pnt1 As Variant
- Dim Pnt2 As Variant
- Dim line As AcadLine
- Dim varCancel As Variant
- hHook = SetWindowsHookEx(WH_KEYBOARD, _
- AddressOf KeyboardProc, 0&, 0)
- Pnt1 = ThisDrawing.Utility.GetPoint(, vbCr & "选择第一点:")
-
- Do
- Pnt2 = ThisDrawing.Utility.GetPoint(Pnt1, vbCr & "选择下一点:")
- Set line = ThisDrawing.ModelSpace.AddLine(Pnt1, Pnt2)
- Pnt1 = Pnt2
- Loop
- Exit_Here:
- Call UnhookWindowsHookEx(hHook)
- Exit Sub
- Err_Control:
- Select Case Err.Number
- Case -2147352567
- '按了取消键或其它透明命令
- If EscKey = True Then
- Err.Clear
- Resume Exit_Here
- Else
- Err.Clear
- Resume
- End If
- Case -2147467259
- '右键单击或回车或空格
- Err.Clear
- Resume Exit_Here
- Case Else
- MsgBox Err.Number & Err.Description
- Err.Clear
- Resume Exit_Here
- End Select
- End Sub
以下为模块部分:
- Public Declare Function CallNextHookEx Lib "user32" _
- (ByVal hHook As Long, _
- ByVal nCode As Long, _
- ByVal wParam As Long, _
- ByVal lParam As Long) As Long
- Public Declare Function UnhookWindowsHookEx Lib "user32" _
- (ByVal hHook As Long) As Long
- Public Declare Function SetWindowsHookEx Lib "user32" _
- Alias "SetWindowsHookExA" _
- (ByVal idHook As Long, _
- ByVal lpfn As Long, _
- ByVal hmod As Long, _
- ByVal dwThreadId As Long) As Long
- Public Declare Function PostMessage Lib "user32" _
- Alias "PostMessageA" _
- (ByVal hwnd As Long, _
- ByVal wMsg As Long, _
- ByVal wParam As Long, _
- ByVal lParam As Long) As Long
- Public Const WH_KEYBOARD = 2
- Public Const KBH_MASK = &H20000000
- Public Const WM_LBUTTONDOWN = &H201
- Public Const WM_LBUTTONUP = &H202
- Global hHook As Long
- Global EscKey As Boolean
- Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, _
- ByVal lParam As Long) As Long
- If nCode >= 0 Then
- 'Process keys you want to filter
- If wParam = 27 Then
- EscKey = True
- Else
- EscKey = False
- End If
- End If
- KeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)
- End Function
|
|