Solved

Clicking a button by code (send message / event ?)

Posted on 2002-03-27
5
175 Views
Last Modified: 2010-05-02
Hi you all,

Some system forms ask the user to confirm an action.

If I don't like to be asked, because my unattended app as an Nt4.0 service started that system function. I would like to "click" that confirmation by code.

Once I saw some snippets, searching something like the window title, collecting the captures of buttons and sending something like a click event to the desired one.
Can you help?

Link posting welcomed too.

Thanx a lot.

C.U.,
swdld

0
Comment
Question by:swdld
5 Comments
 
LVL 6

Expert Comment

by:VK
ID: 6899460
Hello swdld !

Usage:

1. AppActivate title[, wait]
2. SendKeys string[, wait]

V.K.
0
 

Accepted Solution

by:
gramire earned 30 total points
ID: 6899597
'this function will do what you want.....

Sub ClickButton()
    Dim msgWindow As Long
    Dim okButton As Long
   
    okButton = 0
   
    'the loop is here in case the window is not present when the sub is called
    Do
        DoEvents
        msgWindow = FindWindow("#32770", "TITLE BAR TEXT")
        'TITLE BAR TEXT = the text from the title bar of the window with the button
       
        okButton = FindWindowEx(msgWindow, 0, "Button", "OK")
        'OK = the text on the button. if the button's text has an underlined letter,
        '   use & before that letter. for example if you have "Yes" with the "Y"
        '   underlined, you'd use "&Yes"
    Loop Until okButton <> 0


    Call SendMessage(okButton, WM_KEYDOWN, VK_SPACE, 0&)
    Call SendMessage(okButton, WM_KEYUP, VK_SPACE, 0&)
End Sub





'these are the function and constant declarations you need:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public 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

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const VK_SPACE = &H20

Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101


These, and many other API functions *WERE* found at www.vbapi.com but the owner discontinued the project. I remember he offered his entire site for download on a single zip. I have that file. It's about 1.39MB. If anybody needs it, let me know. I believe the site was updated at least once after saved the zip, so I may not have the latest version.
0
 
LVL 27

Expert Comment

by:Ark
ID: 6909395
Private Const BM_CLICK = &HF5
SendMessage hButton, BM_CLICK, 0, ByVal 0&
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7078704
Greetings.

This question has been locked with a Proposed Answer, and remains open today.

If the Proposed Answer did not serve your needs, please reject it and comment with an update.  If the Proposed Answer helped you, please accept it to grade and close this question.  If you need help splitting points between multiple experts, please comment here with details so we can help you.

EXPERTS ->  Please guide me here in terms of closing recommendations if the Asker does not respond in 4 days.

Thanks to all,
Moondancer - EE Moderator
0
 
LVL 1

Author Comment

by:swdld
ID: 7216888
Sorry for not corresponding such a long time,
I moved.
Thanx a lot anyway !

C.U.,
swdld
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now