[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Click button on other application ..URGENT!

Posted on 2005-05-15
13
Medium Priority
?
264 Views
Last Modified: 2011-10-03
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
Comment
Question by:nffvrxqgrcfqvvc
  • 6
  • 4
  • 3
13 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 14007503
Does the button have a caption?
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 14007530
You did try this line with a Capital B on button right?

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

Author Comment

by:nffvrxqgrcfqvvc
ID: 14007531
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Author Comment

by:nffvrxqgrcfqvvc
ID: 14007536
Yes I tried with capital letter Button but it doesn't work.
0
 
LVL 29

Author Comment

by:nffvrxqgrcfqvvc
ID: 14007565
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
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 2000 total points
ID: 14007602
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
 
LVL 29

Author Comment

by:nffvrxqgrcfqvvc
ID: 14007652
Hey that seems to work....Let me just run a few more tests...looks like you got the points vinnyd79 thank you
0
 
LVL 7

Expert Comment

by:Burbble
ID: 14007688
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
 
LVL 7

Expert Comment

by:Burbble
ID: 14007693
It's scrolling through all of the "button" items in the program instance isn't it?

Disregard what I said :)
0
 
LVL 29

Author Comment

by:nffvrxqgrcfqvvc
ID: 14007719
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
 
LVL 28

Expert Comment

by:vinnyd79
ID: 14007754
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
 
LVL 7

Expert Comment

by:Burbble
ID: 14007759
^--- just thought of that :)

0
 
LVL 29

Author Comment

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

Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question