🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by Chris W Wed, 02 Apr 2003 17:09
More sending mouse clicks?
#17198
Author: Chris W
Date: Wed, 02 Apr 2003 17:09
8 lines
1230 bytes
I have successfully sent a mouse click to a button in another
application.  Windows makes in a bit difficult though.  I can't just
send the mouse click to the application window handle at the correct (x,
y) location to click on a button, I have to find the window handle of
the button and send the mouse click to its handle.  I don't suppose
there is an easier way?

Chris W
Re: More sending mouse clicks?
#17199
Author: Remy Lebeau (TeamB)
Date: Wed, 02 Apr 2003 17:36
35 lines
2073 bytes
"Chris W" <chrisw3@cox.net> wrote in message
news:3E8B193A.11681D9C@cox.net...
> I can't just send the mouse click to the application window
> handle at the correct (x, y) location to click on a button,
> I have to find the window handle of the button and send
> the mouse click to its handle.

Correct.  That is how Windows is designed to work - each visual control that
can receive user input has its own handle which messages are directed to
individually.

> I don't suppose there is an easier way?

Nope.  You have to locate the main window at the desired screen coordinates
first, and then recursive iterate through its child windows until you find
the one you are looking for.  For example:

    POINT p = some screen coordinates;
    HWND hWnd = ::WindowFromPoint(p);
    while( hWnd != NULL )
    {
        POINT p2 = p;
        ::ScreenToClient(hWnd, &p2);
        HWND hChild = ::ChildWindowFromPoint(hWnd, p2);
        if( hChild == NULL || hChild == hWnd )
            break;
        hWnd = hChild;
    }

    if( hWnd != NULL )
        // send messages to hWnd as needed


Gambit
Re: More sending mouse clicks?
#17202
Author: Chris W
Date: Wed, 02 Apr 2003 19:39
27 lines
1764 bytes
Does that mean that windows executes simmilar code to your example every time
the user clicks the mouse?

Chris W

"Remy Lebeau (TeamB)" wrote:

> Nope.  You have to locate the main window at the desired screen coordinates
> first, and then recursive iterate through its child windows until you find
> the one you are looking for.  For example:
>
>     POINT p = some screen coordinates;
>     HWND hWnd = ::WindowFromPoint(p);
>     while( hWnd != NULL )
>     {
>         POINT p2 = p;
>         ::ScreenToClient(hWnd, &p2);
>         HWND hChild = ::ChildWindowFromPoint(hWnd, p2);
>         if( hChild == NULL || hChild == hWnd )
>             break;
>         hWnd = hChild;
>     }
>
>     if( hWnd != NULL )
>         // send messages to hWnd as needed
>
> Gambit
Re: More sending mouse clicks?
#17203
Author: Remy Lebeau (TeamB)
Date: Wed, 02 Apr 2003 20:36
14 lines
1549 bytes
"Chris W" <chrisw3@cox.net> wrote in message
news:3E8B3C6D.791BD13D@cox.net...
> Does that mean that windows executes simmilar code to
> your example every time the user clicks the mouse?

I have no clue.  That is part of Windows' internals.  It does whatever it
does.  I would suspect that it has a slightly more direct way of doing it
since it knows the internals of each individual window and how they work
internally, while the rest of us are stuck using the public API that is
exposed for general use.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads