SetFocus

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
andy3858
Newbie
Posts: 1
Joined: Sat Jun 21, 2003 11:14 am

SetFocus

Post by andy3858 » Sat Jun 21, 2003 11:19 am

I'm trying to use SetFocus to select the correct window before running a macro, but infuriatingly the application window in question has a title that is always dynamic - it starts with the current time and has no other fixed content. As a result I can't even use the SetFocus wild card character.

Can anyone suggest a workaround for this - or suggest another alternative function that will give the focus to the correct application?

Many thanks.

Andy

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jun 21, 2003 4:02 pm

Have you tried FindWindowWithText> OR GetActiveWindow> ?

Try something like this:
======================
FindWindowWithText>UniqueText,1,Title

OR

GetActiveWindow>Title,TopX,TopY

SetFocus>%Title%*
.....
.....
.....
=============================

From the Macro Scheduler Help files:
=============
FindWindowWithText>text_to_find,setfocus_flag,result_variable

This function attempts to locate a window containing somewhere within it the text specified in text_to_find. setfocus_flag can be set to 1 or 0. If set to 1, the function will activate the window it finds containing the specified text. If a window is found, result_variable will contain the found window's title text. If no window is found it will contain "NOT FOUND".

NB. Not all text can be detected successfully. Some applications, such as Word Processors, in order to provide their more complex functionality have to display text in the form of graphics, so do not manifest textual data to other applications. FindWindowWithText uses the same routines as the View System Windows tool. So to see what text can be detected at any particular time use the View System Windows tool.

This function is useful when an application has two windows with the same name, and allows the correct one to be located and focused.
===========
GetActiveWindow>window_title,X,Y[,Width,Height]

Retrieves information about the current active window. The window title, and top left coordinates of the active window are stored in window_title, X and Y.

The optional parameters Width and Height will return the width and height of the window respectively.

If GAW_TYPE is set to 1 (default is 0) this command will retrieve information about the active child window of the active foreground window. For default behaviour set GAW_TYPE back to 0.
=======================
Hope this helps........good luck,
Bob

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts