Solved

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

Posted on 2002-03-27
5
176 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now