• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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!
0
nffvrxqgrcfqvvc
Asked:
nffvrxqgrcfqvvc
  • 6
  • 4
  • 3
1 Solution
 
vinnyd79Commented:
Does the button have a caption?
0
 
vinnyd79Commented:
You did try this line with a Capital B on button right?

EZ_Image_Still = FindWindowEx(x, 0&, "Button", vbNullString)
0
 
nffvrxqgrcfqvvcAuthor Commented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
nffvrxqgrcfqvvcAuthor Commented:
Yes I tried with capital letter Button but it doesn't work.
0
 
nffvrxqgrcfqvvcAuthor Commented:
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
0
 
vinnyd79Commented:
Are you getting a value for x after this line?

x = FindWindow("#32770", vbNullString)


If so,try running this utility to see what other windows might be running with the #32770 class.Some of them might not be visible.

http://www.vbcodemagician.dk/tips/system_enumwindow.htm

Also,Can the window be found with this?

x = FindWindow(vbNullString, "EZShowtime MMS 1.1")
0
 
nffvrxqgrcfqvvcAuthor Commented:
Hey that seems to work....Let me just run a few more tests...looks like you got the points vinnyd79 thank you
0
 
BurbbleCommented:
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...
0
 
BurbbleCommented:
It's scrolling through all of the "button" items in the program instance isn't it?

Disregard what I said :)
0
 
nffvrxqgrcfqvvcAuthor Commented:
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.
0
 
vinnyd79Commented:
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&)
0
 
BurbbleCommented:
^--- just thought of that :)

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

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now