Link to home
Start Free TrialLog in
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

asked on

Click button on other application ..URGENT!

Hello I am writing an application for a webcam, the software it came with lacks a feature, which is it only allows to take a snapshot if your at your computer, however I wrote a small application to wait for 10 -20 seconds and then take a snapshot. In order to do this I am simulating a mouse up and down click.  When i originally was doing it I would use the Mouse_Event API and just put the mouse directly over the button and when it reached 10 seconds it would click the button, but then I didn't want to always just put the mouse at the position of the button so I took the approach of finding the window and sending an mouse down and mouse up command using API..

It worked when I was testing it but then when I closed the application and restarted it it wouldn't find the button anymore and it doesn't click it because the button can't be found.  The window doesn not have a common form structure or a title...

I am wondering why this happened and how can I get it to simulate a mouse click at the buttons position every time. The button is odd in that it finds it as:

Window Class Name "Button"
Parent Win Class Name "#32770"

I know that the window handle changes every time..so Thats why I use the findwindow API but the problem is it worked before but when I went to try it again it didn't find the button..below is the code. Apparently it doesnt even find the main window or any child windows for that matter..anyone have any ideas??

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName 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

Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202


Private Sub Timer1_Timer()
Dim x As Long
Dim EZ_Image_Still As Long

x = FindWindow("#32770", vbNullString)
EZ_Image_Still = FindWindowEx(x, 0&, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)
Call SendMessageLong(EZ_Image_Still, WM_LBUTTONDOWN, 0&, 0&)
Call SendMessageLong(EZ_Image_Still, WM_LBUTTONUP, 0&, 0&)

Timer1.Enabled = False

If EZ_Image_Still = 0 Then
       MsgBox "EZ Showtime MMS 1.1 application is not started, please run the EZ Showtime software before capturing still images.", vbInformation, "EZ Showtime Error"
   
    Exit Sub
End If

End Sub



The code above worked for some reason but it only worked once..when I restarted my computer and tried it again it couldnt find the window button.

Also If i remember correctly that #32770 referes to a msgbox command button but I don't remember, however the button the form is graphical not a msgbox button..

Although the code is in the timer it only fires once and then is disabled..I am stumped because it worked before and now it doesn't work.

I know that allot of applications have the "Button" window but I disabled all running applications as well just incase it might of been detecting another apps button. But that wasnt the case it still didn't work.


Thanks!
Avatar of vinnyd79
vinnyd79

Does the button have a caption?
You did try this line with a Capital B on button right?

EZ_Image_Still = FindWindowEx(x, 0&, "Button", vbNullString)
Avatar of nffvrxqgrcfqvvc

ASKER

I dont believe it does..this is the API spy statistics

Window Handle: 525656
Window Text ""
Window Class Name: "Button"
Parent Win Handle: 2098228
Parent Win Text: "EZShowtime MMS 1.1"
Parent Win Class Name: "#32770"

I know all the handles change every time the application is restarted.

The software is EZ Showtime MMS 1.1
form Ezonics corp

www.ezonics.com
Yes I tried with capital letter Button but it doesn't work.
There is a photo here of what the application looks like...

http://www.shopezonics.com/PhotoGallery.asp?ProductCode=EZ%2D913s&PhotoNumber=2#largerphoto

The button i am trying to similuate a mouse click is the third button from the left and the first button on the right..under the baby picture if its of any help seeing it visually
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey that seems to work....Let me just run a few more tests...looks like you got the points vinnyd79 thank you
Do you need the line:

EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "button", vbNullString)

repeated so many times? If not, they are just taking up more resources and time, and I'd recommend deleting them...
It's scrolling through all of the "button" items in the program instance isn't it?

Disregard what I said :)
Yea..I need all of them otherwise the wrong button is clicked. I know it looks confusing at first thought so I understand why you thought that way.
couldn't you throw it in a loop:

EZ_Image_Still = FindWindowEx(x, 0&, "Button", vbNullString)

Dim c as integer
For c = 1 To 18
    EZ_Image_Still = FindWindowEx(x, EZ_Image_Still, "Button", vbNullString)
Next c

Call SendMessageLong(EZ_Image_Still, WM_LBUTTONDOWN, 0&, 0&)
Call SendMessageLong(EZ_Image_Still, WM_LBUTTONUP, 0&, 0&)
^--- just thought of that :)

' The loop works as well as changing the original line to this line :    x = FindWindow(vbNullString, "EZShowtime MMS 1.1")

Thanks