Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam 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
Const WM_COMMAND = &H111
Private iTime As Integer
'Constants Declarations
Private Const BM_CLICK As Long = &HF5 'To click a button
Private Const WM_CLOSE As Long = &H10
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
'This function when it is called it tries to close my appliction
Private Sub Command2_Click()
Dim window As Long
window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
PostMessage window, WM_COMMAND, 32831, 0
End Sub
''this will click yes to closing confirmation when it pops up
''and also re opens my application again
Private Sub Timer1_Timer()
Dim x As Long, editx As Long
Dim button As Long
x = FindWindow("#32770", "Exit?")
button = FindWindowEx(x, 0&, "Button", "&Yes")
Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)
'after complet close of my application . It loads it again for a new 20 sec session
If x Then
' SendMessage x, WM_CLOSE, 0&, 0&
Shell "C:\Program Files\my.\xyz.exe"
[B] Call main[/B]==> clicks on my new applicaton button login
End If
End Sub
'starts a new 20 seconds session life time for my application
[B]Private Sub Command1_Click()
Timer2.Interval = 1000
Timer2.Enabled = True
'Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub[/B]
Private Sub Timer2_Timer()
iTime = iTime + 1
Debug.Print iTime
If iTime >= 10 Then
Debug.Print "END!"
[B] Command2_Click[/B]= calls command 2 to close my application
Timer2.Interval = 0
Timer2.Enabled = False
End If
End Sub
Sub main()
Dim hParent As Long
Dim hChild As Long
Do
hParent = FindWindow("#32770", "Welcome")
DoEvents
Loop Until hParent
If Not hParent = 0 Then
'To find the button in pARENT window
hChild = FindWindowEx(hParent, 0, "Button", "&Login")
'If button found then click it.
If hChild <> 0 Then
'Now we clicked the button
Call SendMessage(hChild, BM_CLICK, 0, 0)
End If
End If
End Sub