Option Explicit 'BY zzyong00(阿勇) '寻找窗口列表中第一个符合指定条件的顶级窗口(在vb里使用:FindWindow最常见的一个用途是获得ThunderRTMain类的隐藏窗口的句柄;该类是所有运行中vb执行程序的一部分。获得句柄后,可用api函数GetWindowText取得这个窗口的名称;该名也是应用程序的标题) Private Declare Function FindWindow _ Lib "user32" _ Alias "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long'在窗口列表中寻找与指定条件相符的第一个子窗口 Private Declare Function FindWindowEx _ Lib "user32" _ Alias "FindWindowExA" (ByVal hWnd1 As Long, _ ByVal hWnd2 As Long, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long'取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性) Private Declare Function GetWindowText _ Lib "user32" _ Alias "GetWindowTextA" (ByVal hwnd As Long, _ ByVal lpString As String, _ ByVal cch As Long) As Long'调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。SendMessageBynum, SendMessageByString是该函数的“类型安全”声明形式 Private Declare Function SendMessage _ Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long'暂停线索 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const BM_CLICK As Integer = &HF5 'button点击消息BM_clickPrivate Sub AutoDialer1() On Error GoTo ToExit '打开错误陷阱 '------------------------------------------------ Shell "c:\windows\system32\rasphone -d 长城宽带", vbNormalFocus DoEvents Sleep 1000 Dim h As Long, h2 As Long h = FindWindow("#32770", "连接 长城宽带") ' If h = 0 Then Exit Sub h2 = FindWindowEx(h, 0&, "Button", vbNullString) Dim s As String * 255, l As Long l = GetWindowText(h2, s, 255) s = Left(s, l) Do Until InStr(s, "连接") Or h2 = 0 h2 = FindWindowEx(h, h2, "Button", vbNullString) l = GetWindowText(h2, s, 255) s = Left(s, l) Loop If h2 = 0 Then Exit Sub SendMessage h2, BM_CLICK, ByVal 0&, 0& '------------------------------------------------ Exit Sub '---------------- ToExit: Resume NextEnd SubPrivate Sub AutoDialer2() On Error GoTo err1 Dim pid As Long pid = Shell("c:\windows\system32\rasphone -d 长城宽带", vbNormalFocus) DoEvents Sleep 1000 AppActivate pid SendKeys "%c", True '按键消息必须在控件返回到过程之前加以处理 Exit Suberr1: Debug.Print Err.Description Err.ClearEnd SubSub Main() AutoDialer2 AutoDialer1 End Sub
'BY zzyong00(阿勇)
'寻找窗口列表中第一个符合指定条件的顶级窗口(在vb里使用:FindWindow最常见的一个用途是获得ThunderRTMain类的隐藏窗口的句柄;该类是所有运行中vb执行程序的一部分。获得句柄后,可用api函数GetWindowText取得这个窗口的名称;该名也是应用程序的标题)
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long'在窗口列表中寻找与指定条件相符的第一个子窗口
Private Declare Function FindWindowEx _
Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long'取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)
Private Declare Function GetWindowText _
Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long'调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。SendMessageBynum, SendMessageByString是该函数的“类型安全”声明形式
Private Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long'暂停线索
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const BM_CLICK As Integer = &HF5 'button点击消息BM_clickPrivate Sub AutoDialer1() On Error GoTo ToExit '打开错误陷阱 '------------------------------------------------
Shell "c:\windows\system32\rasphone -d 长城宽带", vbNormalFocus DoEvents
Sleep 1000 Dim h As Long, h2 As Long h = FindWindow("#32770", "连接 长城宽带") ' If h = 0 Then Exit Sub
h2 = FindWindowEx(h, 0&, "Button", vbNullString) Dim s As String * 255, l As Long l = GetWindowText(h2, s, 255)
s = Left(s, l) Do Until InStr(s, "连接") Or h2 = 0
h2 = FindWindowEx(h, h2, "Button", vbNullString)
l = GetWindowText(h2, s, 255)
s = Left(s, l)
Loop If h2 = 0 Then Exit Sub
SendMessage h2, BM_CLICK, ByVal 0&, 0& '------------------------------------------------
Exit Sub '----------------
ToExit: Resume NextEnd SubPrivate Sub AutoDialer2() On Error GoTo err1 Dim pid As Long pid = Shell("c:\windows\system32\rasphone -d 长城宽带", vbNormalFocus) DoEvents
Sleep 1000 AppActivate pid
SendKeys "%c", True '按键消息必须在控件返回到过程之前加以处理 Exit Suberr1:
Debug.Print Err.Description
Err.ClearEnd SubSub Main() AutoDialer2
AutoDialer1
End Sub
谢谢代码,如何用代码断开网络呢
SendKeys "%c", True '按键消息必须在控件返回到过程之前加以处理
这二句的引用在哪里