Click Button On Other App (AOL Toolbar)

Posted on 2006-03-30
Last Modified: 2010-04-07
Ok, first off here's my code.  The SetFocusAPI wasn't in there originally and doesn't appear to have helped at all.

Call SendMessage(addresshWnd, WM_SETTEXT, 0&, location.Text)
Call SetFocusAPI(addresshWnd)
Call SendMessage(pns, WM_LBUTTONDOWN, 0, 0&)
Call SendMessage(pns, WM_LBUTTONUP, 0, 0&)

The problem is that visually it works.  I run it, the text is put where I want it in the AOL Toolbar (AOL 9.0)
and when I put a sleep in between the mouse events I can actually SEE it pushing the button and releasing.

Problem is nothing happens.  If I do it manually obviously it does work.  So here I am.. lost.. any ideas?
Question by:adamwj
    LVL 28

    Expert Comment

    Have you tried sending a BM_CLICK message to the button?

    Author Comment

    Yea, I tried that earlier.  I should have mentioned that.

    Same result (nothing).  I'm by no means an expert but seeing it visually happen makes me wonder why it doesn't work. :|

    Author Comment

    I just found out if I put a 3 second sleep between the buttonup/buttondown and move the mouse cursor over the icon/button during that sleep it will actually work.

    Not sure where to go from here.  Does that sound like normal behavior?  
    LVL 5

    Accepted Solution

    Between the events, move the mouse over the button using this and the move the mouse back, that'll probably work...
    LVL 28

    Expert Comment

    Have you tried using PostMessage instead of SendMessage?

    Author Comment

    Vinny I did try that with the same result.

    Atan, that ClientToScreen api was exactly what I needed.  Here's what I have now (working).  Hopefully someone else finds this useful in a search.

    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    Const MK_LBUTTON = &H1

    Dim p2 as POINTAPI

    ClientToScreen pns, p2
    SetCursorPos p2.x, p2.y
    Call PostMessage(pns, WM_LBUTTONDOWN, MK_LBUTTON, 0)
    Call PostMessage(pns, WM_LBUTTONUP, 0, 0)

    pns is the hwnd of the aol button I want to click.  

    Thanks everyone for the input!
    LVL 5

    Expert Comment

    Glad to help :)

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    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…
    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…

    746 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

    19 Experts available now in Live!

    Get 1:1 Help Now