Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simulate mouse?

Status
Not open for further replies.

MartDawg

Programmer
Jan 14, 2004
33
US
I have a vb app I am trying to stress test. I fire it off with a batch file.

When the vb application ends, a message box is displayed, in order to end the application the message box must be pressed.

Is there a way I can make that button be depressed, either through a seperate vb app. Maybe simulate a mouse button.
 
The easiest way would be to just not pop up the message box during the stress test.

If boolStressTestRunning = false then
msgbox "Your Message"
else
'just close
end if

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I'd rather be able to simulate if at all possible.
 
Can you not use a form as a message box, and call the Button1_Click event from a timer to give enough viewing time to see the form/messagbox appeared. I don't know if you can call a button click on a messagebox?
 
Try this, it will close the message box after the timer times out.



'Form Code
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Private Sub cmdShowMsg_Click()
'// this shows a messagebox that will be dismissed after 4 seconds

'// set the callback timer and pass our application defined ID (NV_CLOSEMSGBOX)
'// set the time for 4 seconds (4000 microseconds)
SetTimer hWnd, NV_CLOSEMSGBOX, 4000, AddressOf TimerProc

'// call the messagebox function

MsgBox "Watch this message box close itself after four seconds.", vbExclamation + vbOKOnly + vbDefaultButton1, "Self Closing Message Box"

'// call the messagebox function
' If MsgBox("Watch this message box close itself after four seconds.", vbRetryCancel + vbDefaultButton1, "Self Closing Message Box") = vbRetry Then
' MsgBox "Retry!"
' Else
' MsgBox "Cancel"
' End If



End Sub

'Module Code
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
'// Message we receive telling us to close the message box
Public Const NV_CLOSEMSGBOX As Long = &H5000&
Public Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
'// this is a callback function. This means that windows "calls back" to this function
'// when it's time for the timer event to fire
'// first thing we do is kill the timer so that no other timer events will fire
KillTimer hWnd, idEvent
'// select the type of manipulation that we want to perform
Select Case idEvent
Case NV_CLOSEMSGBOX '// we want to close this messagebox after 4 seconds
Dim hMessageBox As Long
'// find the messagebox window
'// change the text to whatever the title of the message box is
hMessageBox = FindWindow("#32770", "Self Closing Message Box")
'// if we found it make sure it has the keyboard focus and then send it an enter to dismiss it
If hMessageBox Then
Call SetForegroundWindow(hMessageBox)
'// this will result in the default option being chosen
SendKeys "{enter}"
End If
End Select
End Sub
 
thanks for the help everybody, i ended up doing something in wscript to send the enter key....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top