VB窗口中一个命令调用另一命令
读这个贴【请问能将cad窗口设为当前窗口吗】想将exe窗口调用至前台,捣鼓了一天,百度到一句话任务栏的窗口API 中的bringwindowtotop SetWindowPos SetForegroundWindow无法实现将其调至前台,遂放弃
从这个 和 学习了可以用如题的用法,实现了VB--->LSP---->VB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;分割线2020-05-29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;仅仅填加了备注,程序无实际变化 当年写这句VB--->LSP---->VB 现在看来我自己都有点莫名其妙
'一般情况下,VB中运行lisp命令只能放入程序的末端如Command1
'此程序示例实现了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(, ".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()'==================================================
'时间长了,加个备注
'1.form_load的内容,同理 也可实现调用Command1
'2.如调用command1的内容,也就是lisp命令可以前置 ,再运行其他vb内容
'==================================================
End Sub
Private Sub Form_Load()
'==================================================
'时间长了,加个备注
'通过form_load启动调用了 command2 命令,如将form_load的内容放入一个命令Command3中,
'即Command3可以调用command2 命令
'==================================================
'寻找按钮句柄
'
'具体代码内容根据软件的结构不同而不同,参考SPY++中目标软件的结构图
'
Dim hTmp As Long
hTmp = FindWindow(vbNullString, "12345") ' 12345 为窗体名字' findwindow(vbnullstring,"窗体名字")
If hTmp0 Then
hDest = FindWindowEx(hTmp, 0, vbNullString, "Command2")
End If
If hDest0 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
**** Hidden Message ***** Appactivate acadapp.Caption
阿勇老师的东西很很高端,是不是调用CAD窗口至当前?请阿勇老师给一个示例链接 谢谢
最初想实现在CAD中调用任务栏中的exe窗口至前台,未实现,只好用taskkill 关闭进程,重启命令
主楼的程序是想分享下 在同一个窗口下,一个命令调用另外一个命令的示例,或许论坛上有,不过没有看到,这个示例程序还是有点用处.比如sendcommand lisp程序只能放在最后,如果在lisp程序后面还想再做点什么之类就可以用这个调用下 呵呵 zzyong00说的是对的
用CAD2006作的实验,代码如下:
'将cad激活到当前
Private Sub Command1_Click()
Appactivate "AutoCAD"
End Sub
回帖是一种美德!感谢楼主的无私分享 谢谢
页:
[1]