Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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