Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal WParam As Long, lParam As Any) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByRef lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Const BM_CLICK = &HF5
Const WM_GETTEXT = &HD
Dim gg_2, m
Sub Main()
m = 1
time1 = Now + TimeValue("00:00:10")
Do Until gg_2 <> 0 Or Now >= time1
If EnumWindows(AddressOf EnumProc1, 0) = 0 Then
Else
End If
DoEvents
Loop
End Sub
Public Function EnumProc1(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
Dim s As String
s = String(255, 0)
GetClassName app_hwnd, s, Len(s)
If s Like "*32770*" Then
If EnumChildWindows(app_hwnd, AddressOf EnumchildProc2, 0) = 0 Then
gg_2 = FindWindowEx(app_hwnd, 0, "Button", "否(&N)")
If gg_2 <> 0 Then SendMessage gg_2, BM_CLICK, 0, 0
'SetFocus (gg_2)
If gg_2 <> 0 Then EnumProc1 = False Else EnumProc1 = True
Else
EnumProc1 = True
End If
'End If
Else
EnumProc1 = True
End If
End Function
Public Function EnumchildProc2(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
Dim s As String
s = String(255, 0)
SendMessage app_hwnd, WM_GETTEXT, 255, ByVal s
If s Like "*请问您真的要这样操作*" Then
Open "d:\" & m & ".txt" For Output As #1 '这一段和m是为了检测错误加进去的。当调试时,只找到一次s,只有一个m文件,然后可以点击按钮。当生产EXE文件后,同样的s能找到2000次,能生成2000个m文件,并且内容是一样的。。最后按钮也没点到。
Print #1, GetParent(app_hwnd)
Print #1, app_hwnd
Print #1, s
Close #1
m = m + 1
EnumchildProc2 = False
Else
EnumchildProc2 = True
End If
End Function