Aaron,

My concern about the filter approach is that it doesn't seem very specific.
Given the parameters you describe, the chances of the filter returning more
than one hit seems substantial - this is why I use control ID values a lot,
when I know I'm dealing with a well-behaved application anyway.

Having said all that, you've given me the solution I need by inference.  If
I grab the handle of my desired window based on its control ID (I've got
that routine working well now), I can then use that handle to find the
rectangle coordinates as per your suggestion - thanks. 

I might also try the messaging approach suggested by Marlon ad see if either
method has any significant benefits/drawbacks.

Best wishes.

Tim Burgess
Raised Bar Ltd
Phone:  +44 (0)1827 719822

Don't forget to vote for improved access to music and music technology at

http://www.raisedbar.net/petition.htm
 
-----Original Message-----
From: Aaron Smith [mailto:[EMAIL PROTECTED] 
Sent: 11 October 2008 18:58
To: gw-scripting@gwmicro.com
Subject: Re: Automating the mouse

The Windows object has several Filter methods that let you find a specific
window. If you know the window's class name and module name, you can use the
FilterByClassAndModule. If you don't know the class name, you can use
FilterByName or FilterByTitle (although Title is going to be a little slower
than the others).

Once you have a window, you can get its rectangle, and the move the mouse to
the top left corner. Alternatively, you can calculate the middle of the
window's rectangle, and move the mouse there. Then do your mouse click.

Assuming that you do in fact know the class name and the module name, and
the window you're looking for is a child of the active window, I would do
the following:

Dim myFilteredWins : Set myFilteredWins =
ActiveWindow.FilterByClassAndModule(myClass, myModule)

If myFilteredWins.Count = 1 Then        
        ' Found one match
        Dim myWin : Set myWin = myFilteredWins(1)
        ' Get the window's rectangle
        Dim myWinRect : Set myWinRect = myWin.Rectangle
        ' The pointer needs a screen point, so get the
        ' screen rectangle of myWinRect
        Dim myScreenRect : Set myScreenRect = myWinRect.ScreenRectangle
        ' Now move the mouse
        Mouse.Position = ScreenPoint(myScreenRect.Left, myScreenRect.Top)
        Mouse.Click mbLeft, 1
End If

There's not much bulletproofing there, but you get the idea. You could also
store the current mouse position before moving it, and then restoring it
after the click. There are lots of possibilities.

Aaron

Tim Burgess wrote:
> Hi,
> 
> I need to locate a sub-window, move the mouse onto it then perform a 
> single left click.  I have the following code:
> 
> Dim cCursor, hWnd
> 
> ' Save the current active cursor
> cCursor = ActiveCursorType
> ActiveCursorType = ctMousePointer
> Find( hWnd)
> Mouse.Click(  mbLeft, 1)
> ' Go back to the cursor the user was using ActiveCursorType = cCursor
> 
> I realise that the Find method isn't going to do what I want, i.e. 
> position the active cursor (the mouse in this case) on the window, if 
> found, but I can't see a way of achieving this result.
> 
> Best wishes.
> 
> Tim Burgess
> Raised Bar Ltd
> PO Box 4442
> Atherstone
> Warwickshire
> CV9 9AT
> 
> Phone:  +44 (0)1827 719822
> Email:  [EMAIL PROTECTED]
> Web:  http://www.raisedbar.net
> 
> Don't forget to vote for improved access to music and music technology 
> at
> 
> http://www.raisedbar.net/petition.htm
>  
> 

--
To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information pertinent to
your situation when submitting a problem report to the GW Micro Technical
Support Team.

Aaron Smith
GW Micro
Phone: 260/489-3671
Fax: 260/489-2608
WWW: http://www.gwmicro.com
FTP: ftp://ftp.gwmicro.com
Technical Support & Web Development

Reply via email to