本帖最后由 Kye 于 2020-5-29 21:35 编辑
读这个贴【请问能将cad窗口设为当前窗口吗】http://bbs.mjtd.com/forum.php?mod=viewthread&tid=110889&fromuid=7303474
想将exe窗口调用至前台,捣鼓了一天,百度到一句话任务栏的窗口API 中的bringwindowtotop SetWindowPos SetForegroundWindow无法实现将其调至前台,遂放弃
从这个https://zhidao.baidu.com/question/1493962773300152419.html 和http://bbs.csdn.net/topics/390328728 学习了可以用如题的用法,实现了VB--->LSP---->VB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;分割线2020-05-29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;仅仅填加了备注,程序无实际变化 当年写这句VB--->LSP---->VB 现在看来我自己都有点莫名其妙
'一般情况下,VB中运行lisp命令只能放入程序的末端如Command1<VB其他内容+LISP 构成了完整VB命令>
'此程序示例实现了lisp命令前置即 [完整VB 命令<含LISP命令>]+[VB其他内容构成一个新的VB命令 '也就是VB命令==[完整VB 命令<含LISP命令>]+[VB其他内容] 完成 lisp命令前置
- Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
- ByVal lpClassName As String, _
- ByVal lpWindowName As String) As Long
- Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
- ByVal hWnd1 As Long, _
- ByVal hWnd2 As Long, _
- ByVal lpsz1 As String, _
- ByVal lpsz2 As String) As Long
- Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" ( _
- ByVal hwnd As Long, _
- ByVal wMsg As Long, _
- ByVal wParam As Long, _
- ByVal lParam As Long) As Long
- Private Const WM_LBUTTONDOWN As Long = &H201
- Private Const WM_LBUTTONUP As Long = &H202
- Dim hDest As Long '目标按钮句柄
- Private Sub Command1_Click()
- On Error GoTo ErrHandler
-
-
- '''连接cad
- Dim acadapp As Object 'AcadApplication
- Dim Thisdrawing As Object 'AcadDocument
- ' Dim thisDrawing As Object
- Set acadapp = GetObject(, "AutoCAD.Application")
- If Err Then
- Err.Clear
- Set acadapp = CreateObject("AutoCAD.Application")
- If Err Then
- MsgBox Err.Description
- End
- Exit Sub
- End If
- End If
- acadapp.Visible = True
- Set Thisdrawing = acadapp.ActiveDocument
- Thisdrawing.SendCommand "TEST" & vbCr '应该改进cad程序运行成功应该将这些数据从库中删除
- ErrExit:
-
- Exit Sub
-
- ErrHandler:
- MsgBox "运行时发生意外,请检查AutoCAD文件是否打开!", vbCritical, "提示"
- GoTo ErrExit
- End Sub
- Private Sub Command2_Click()
- MsgBox "测试怎么样?"
- End Sub
- Private Sub Command3_Click()'==================================================
- '时间长了,加个备注<2020-05-29>
- '1. form_load的内容<示例中调用command2>,同理 也可实现调用Command1
- '2. 如调用command1的内容<即lisp>,也就是lisp命令可以前置 ,再运行其他vb内容
- '==================================================
- End Sub
- Private Sub Form_Load()
- '==================================================
- '时间长了,加个备注<2020-05-29>
- '通过form_load启动调用了 command2 命令,如将form_load的内容放入一个命令Command3中,
- '即Command3可以调用command2 命令
- '==================================================
- '寻找按钮句柄
- '
- '具体代码内容根据软件的结构不同而不同,参考SPY++中目标软件的结构图
- '
- Dim hTmp As Long
-
- hTmp = FindWindow(vbNullString, "12345") ' 12345 为窗体名字' findwindow(vbnullstring,"窗体名字")
-
- If hTmp <> 0 Then
- hDest = FindWindowEx(hTmp, 0, vbNullString, "Command2")
- End If
- If hDest <> 0 Then
- SendClick hDest, 10, 10 '
- Else
- MsgBox "还未找到句柄!"
- End If
- End Sub
- Private Function SendClick(hwnd As Long, mX As Long, mY As Long)
- '发送点击消息
- Dim I As Long
- I = PostMessage(hwnd, WM_LBUTTONDOWN, 0, (mX And &HFFFF) + (mY And &HFFFF) * &H10000)
- I = PostMessage(hwnd, WM_LBUTTONUP, 0, (mX And &HFFFF) + (mY And &HFFFF) * &H10000)
- End Function
|