Well .. I just can't figure out why one would spend lots of resources cauculating a center of a screen of a window, moving the mouse pointer there and clicking it if one just could get the handle of the desired window and sending to it a windows message. It seen more reliable and pretty more optimized... I however am not writting this to shoot anyone ... I am writting this to ask if I am right in the above statement, cinse I am not used to script window eyes. Thanks, Marlon
2008/10/13, Ron Parker <[EMAIL PROTECTED]>: > > You should almost never need the handle of a window if you're working > solely with VBScript. There's almost certainly a better way to do what > you're doing. > > It sounds like you're somehow finding a Control object, then getting > Control.Window.Handle, and then trying to find the Window with that > handle? That'll just get you a reference to the same object you got > from Control.Window; it seems like a rather roundabout way to get back > to where you started from. > > Besides, if you have a Control object, you can use Control.Position, > Control.Width, and Control.Height to get the point at the center. So, > if you have a Control object in the "mycontrol" variable, this should work: > > Set sp = mycontrol.Position.ScreenPoint > sp.X = sp.X + mycontrol.Width / 2 > sp.Y = sp.Y + mycontrol.Height / 2 > > Mouse.Position = sp > > > > Tim Burgess wrote: >> 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: [email protected] >> 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 >> >> > > -- When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
