Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-03-27
5
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 120 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 28

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

Industry Leaders: 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!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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

664 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