windows specific macro, ends if window not in focus

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
akiley

windows specific macro, ends if window not in focus

Post by akiley » Sat Oct 25, 2003 3:53 am

I am a newby with a very basic question. I have a set of macros that I only want to run when a specific program is in the foreground. I don't want MS to bring it to the foreground then run the macro, I want the macro ended if the program isn't in the foreground, and run only if it's currently in the foreground. How do I do this?? I've tried:

Let>WW_TIMEOUT=1
WaitWindowOpen>Qimage [v2003.277]
If>WW_RESULT=FALSE,End

but the macro still seems to run outside of Qimage. I can put a SetFocus at the top, but I don't want the macro to run when I'm not already in Qimage.

Thanks ... Aaron

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Sat Oct 25, 2003 5:59 pm

You have the right idea. Use the "IfWindowOpen" command to see if it's already open.
(It sounds like you don't want to wait until the window opens, you just want to see if it's there or not).

Or, if it's only to check if the window is in the foreground (and not in the background), use the "GetActiveWindow" command to find out which window has focus, which can return the window title. You can then use "Position" command to see if that string contains the substring "Qimage". (If it doesn't, the value will be 0)

You have a lot of options as to exactly what you want... if the window is open, if it's in focus, etc.

Guest

Post by Guest » Sat Oct 25, 2003 7:07 pm

Captive wrote:You have the right idea. Use the "IfWindowOpen" command to see if it's already open.
(It sounds like you don't want to wait until the window opens, you just want to see if it's there or not).

Or, if it's only to check if the window is in the foreground (and not in the background), use the "GetActiveWindow" command to find out which window has focus, which can return the window title. You can then use "Position" command to see if that string contains the substring "Qimage". (If it doesn't, the value will be 0)

You have a lot of options as to exactly what you want... if the window is open, if it's in focus, etc.
Thanks for the help. I'm only wanting to check if Qimage is in the foreground. In other words, if I'm working in Photoshop and I hit my hotkey by accident, I don't want the macro to run. I don't want the marco to set focus to Qimage and run either, because I need to already be working in Qimage and point to a file with my mouse, then run the macro which effects that file. Seems like there should be an idiot switch during macro record that says " only run this macro while xx window is running and in the foreground"

But anyway, I can't figure out how to use "GetActiveWindow" and "Position" to get the result I want. The help file doesn't give much of a beginners explanation or examples. In longhand this is what I want.

GetActiveWindow
if the result above is Qimage* then...
run the rest of my macro
if it's not, pop a message that allows me to abort the macro

... Aaron

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 Oct 25, 2003 9:46 pm

You wrote:
In longhand this is what I want.

GetActiveWindow
if the result above is Qimage* then...
run the rest of my macro
if it's not, pop a message that allows me to abort the macro
:idea: Try something like this:
GetActiveWindow>InFront,X,Y
If>%InFront%=Qimage*,DoRest,End

Label>DoRest
.....
.....
.....
.....

Label>End
A prompt message is not needed, the macro will end automatically.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Guest

Post by Guest » Sat Oct 25, 2003 11:56 pm

bob hansen wrote:You wrote:
In longhand this is what I want.

GetActiveWindow
if the result above is Qimage* then...
run the rest of my macro
if it's not, pop a message that allows me to abort the macro
:idea: Try something like this:
GetActiveWindow>InFront,X,Y
If>%InFront%=Qimage*,DoRest,End

Label>DoRest
.....
.....
.....
.....

Label>End
A prompt message is not needed, the macro will end automatically.
Wow, thanks! It works perfectly. ... Aaron

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