GetActiveWindow> grabs WHAT?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jalbt51
Junior Coder
Posts: 31
Joined: Sat Mar 06, 2004 4:40 pm

GetActiveWindow> grabs WHAT?

Post by jalbt51 » Mon Nov 29, 2004 7:56 pm

How can I use WaitWindowOpen> in WIN_USEHANDLE=1 mode, since the handle of the window just executed is not yet known?

I thought I had this problem of grabbing just the right window solved, but the following script maximizes and then minimizes Macrscheduler instead of notepad. If I can use WaitWindowOpen> perhaps I can force notepad to be the active window grabbed by GetActiveWindow>?


Let>WIN_USEHANDLE=1
ExecuteFile>C:\WINDOWS\notepad.exe
WaitReady>1
GetActiveWindow>window_title,X,Y
Let>justopened=window_title
WindowAction>1,justopened
Wait>0.5
WindowAction>2,justopened
:?

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 » Mon Nov 29, 2004 8:43 pm

Try inserting a WaitWindowOpen>WindowName* command right after your Execute> command.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Nov 29, 2004 8:47 pm

Your script doesn't allow any time for Notepad to open.

In this example WaitWindowOpen using the window title would be easiest.

But if you do need to use handles (perhaps you have other notepad windows open with the same title) use this version of your script:


Let>WIN_USEHANDLE=1
GetActiveWindow>old_window
Run Program>C:\WINDOWS\notepad.exe
Label>waitforchange
GetActiveWindow>window_handle,X,Y
If>window_handle=old_window,waitforchange
Let>justopened=window_handle
WindowAction>1,justopened
Wait>0.5
WindowAction>2,justopened


What this does is get the active window's handle, open notepad and then wait until the handle of the active window changes. i.e. the active window is not what it was before. Now we know we have a new window and can continue.

WaitReady was doing nothing because it was working on the window that was active before notepad started, because you didn't allow time for notepad to start.
MJT Net Support
[email protected]

jalbt51
Junior Coder
Posts: 31
Joined: Sat Mar 06, 2004 4:40 pm

Thanks for Waiting for window to change loop

Post by jalbt51 » Tue Nov 30, 2004 3:10 am

YES! :D Thankyou!
I recognize this kind of waiting for a change, from a similar waiting for a pixel color on a certain spot in a browser window to change, signalling a new window being opened. And then the same spot changing back, signalling the process is complete(I had very iffy results with this in IE, but very good results in mozilla)
I used notepad for simplicity. The real script works with a photo editor called irfan view. It is typically doing other things while I call on it to do something under Macro Scheduler.

Guest

FURTHER ON WAIT, WITH GETACTIVEWINDOW IN WINDOW HANDLE MODE

Post by Guest » Tue Nov 30, 2004 7:23 pm

ALRIGHT:
1. Everything works except Windows Explorer. When I bring THAT up, even with a TEN second delay, Macro Scheduler still thinks that itself is the active window.
2. I can't do without ,X,Y in GetActiveWindow>window_handle,X,Y. That is, using only GetActiveWindow>window_handle screws things up.
3. Is there an advantage in using Label>waitforchange_1 instead of Label>waitforchange1 ?

This script brings up, maximizes, minimizes and closes notepad and wordpad, but it chokes on Explorer, even with a ten second wait.......

Let>WW_TIMEOUT=0
Let>WIN_USEHANDLE=1

GetActiveWindow>old_window
Run Program>C:\WINDOWS\notepad.exe

Label>waitforchange_1
GetActiveWindow>window_handle,X,Y
If>window_handle=old_window,waitforchange_1
Let>justopened_1=window_handle

WindowAction>1,justopened_1
Wait>0.5
WindowAction>2,justopened_1

GetActiveWindow>old_window
Run Program>C:\Program Files\Windows NT\Accessories\wordpad.exe

Label>waitforchange_2
GetActiveWindow>window_handle,X,Y
If>window_handle=old_window,waitforchange_2
Let>justopened_2=window_handle

WindowAction>1,justopened_2
Wait>0.5
WindowAction>2,justopened_2

Wait>1.5
WindowAction>3,justopened_1
WindowAction>3,justopened_2

GetActiveWindow>old_window
Run Program>C:\WINDOWS\explorer.exe

Label>waitforchange_3
GetActiveWindow>window_handle,X,Y
If>window_handle=old_window,waitforchange_3
Let>justopened_3=window_handle

//WaitWindowOpen>justopened_3
Wait>10
WindowAction>1,justopened_3
Wait>0.5
WindowAction>2,justopened_3

WindowAction>3,justopened_3
:?

jalbt51
Junior Coder
Posts: 31
Joined: Sat Mar 06, 2004 4:40 pm

Post by jalbt51 » Tue Nov 30, 2004 7:26 pm

Sorry, I didn't realize that I wasn't automatically logged in when I submitted the above. It's mine- jalbt51. One more thing about the above, that deactivated WaitWindowOpen will stop the whole works if activated!!! :o

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Nov 30, 2004 8:19 pm

No wonder it doesn't work you've left out the X,Y parms. You must provide all the parms that the documentation tell you to provide. Doesn't matter if you don't need to use them, you MUST provide them.

This macro works for me:


Let>WIN_USEHANDLE=1
GetActiveWindow>old_window,x,y
Run Program>C:\WINDOWS\explorer.exe
Label>waitforchange_3
GetActiveWindow>window_handle,X,Y
If>window_handle=old_window,waitforchange_3
Let>justopened_3=window_handle
SetFocus>window_handle
Press ALT
Send> n
Release ALT


This waits for Explorer to open and then minimizes it. You must use the correct syntax for the GetActiveWindow command. And there's also a chance that WindowAction doesn't work with all windows. Here I'm sending ALT-space-n to Explorer to minimize it. Works fine.

In case anyone else should be reading this this technique is usually not necessary. This is just an example of using window handles where you have multiple windows with the same title. Usually we'd do this:

Run>app.exe
WaitWindowOpen>window_title

On my system Windows Explorer starts up with 'My Documents' as the title, so I'd use this.
MJT Net Support
[email protected]

jalbt51
Junior Coder
Posts: 31
Joined: Sat Mar 06, 2004 4:40 pm

THANKYOU and one more question

Post by jalbt51 » Wed Dec 01, 2004 2:36 am

THANKYOU! :D
Everything is smooooth, quick and quiet!
Thanks for explaining send> n (send SPACE n), I would have missed it.
I've always used wait> and WaitWindowOpen> before, but now need to distinguish different irfanview windows- main window, clipboard, thumbnails, etc. Macro Scheduler would sometimes grab (and close) a window I thought was inactive.
One more question: While in WIN_USEHANDLE=0 mode, do I have to say Let>WIN_USEHANDLE=0 again before using WaitWindowOpen>window_title ?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Dec 01, 2004 8:48 am

Yes, if you want to switch back to using window titles remember to reset USE_WINHANDLE back to 0 first:

Let>USE_WINHANDLE=0
MJT Net Support
[email protected]

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