GetActiveWindow - What am I doing wrong?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Jaylee
Junior Coder
Posts: 45
Joined: Wed Feb 08, 2006 4:48 am

GetActiveWindow - What am I doing wrong?

Post by Jaylee » Fri Apr 06, 2007 8:07 am

G'day,

It's been a while since I needed to write any scripts but a major disaster occurred and I find I now have to rewrite a number of scripts I previously had running. With the updated version and a lack of recent experience, I find I'm struggling with seemingly simple script so, please, bear with me.

I am testing to see if Outlook is open using Version 9 on XP SP2.

With Outlook open at the Inbox by default, the following code is doing something strange:

Code: Select all

GetActiveWindow>window_title,X,Y
Position>Outlook,window_title,1,pos
If>pos>0,Found,NotFound
Label>Found
SetFocus>Inbox*
Wait>3
GoTo>End
Label>NotFound
Msg>Didn't Find It
Label>End
Msg>Finished
If I have the Advanced Editor open and run the above script, everything works beautifully. (I have the Wait>3 inserted simply to observe how this operates.) The script locates Outlook, sets the focus on the window, waits for 3 seconds, then goes to the "Finished' messagebox.

On closing the Advanced Editor but remaining in the Macro screen and running the script again, the "Finished" messagebox opens within a split second of clicking the Run button. It doesn't set the focus on the Outlook window or wait 3 seconds. It instantly displays the "Finished" messagebox. Same thing happens if I run the script from the main MS window.

I have opened and closed the Advanced Editor numerous times to test this strange anomaly. I get these two different results simply from running the script with the Advanced Editor either open or not open. No other changes are made to other windows open at the time (other than the obvious differences with MS windows).

Please show me what I'm doing wrong.

TIA. :)

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 06, 2007 8:19 am

Your code is redundant. Your code looks to see if the word "Outlook" is in the title of the active window. If it is, you focus the window. But why would you need to focus a window which is already active? Focused=Active.

Not sure why you are seeing an anomaly but it must be something to do with the name of the active window when the editor is open - perhaps the script is finding it's own window.

Anyway, if you just want some code to see if Outlook Inbox is open and if so focus it, all you need is this:

Code: Select all

IfWindowOpen>Inbox - Microsoft Outlook
  SetFocus>Inbox - Microsoft Outlook
Endif
With some messages to see what it is doing:

Code: Select all

IfWindowOpen>Inbox - Microsoft Outlook
  SetFocus>Inbox - Microsoft Outlook
  MessageModal>Found it
Else
  MessageModal>Not Found
Endif
MessageModal>Finished
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Jaylee
Junior Coder
Posts: 45
Joined: Wed Feb 08, 2006 4:48 am

Post by Jaylee » Fri Apr 06, 2007 8:54 am

Thank you, Marcus.

I greatly appreciate the fast response.

I need to study up as I have been away from writing script for so long (MS has proved VERY reliable at running my poor code up until the recent disaster!) I MUST back-up. I MUST back-up. I'll go and write that another thousand times ...

Enjoy the rest of the Easter break.

:D

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