GetActiveWindow> grabs WHAT?
Moderators: Dorian (MJT support), JRL
GetActiveWindow> grabs WHAT?
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
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
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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.
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]
[email protected]
Thanks for Waiting for window to change loop
YES! 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.
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.
FURTHER ON WAIT, WITH GETACTIVEWINDOW IN WINDOW HANDLE MODE
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
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
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.
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]
[email protected]
THANKYOU and one more question
THANKYOU!
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 ?
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 ?
Yes, if you want to switch back to using window titles remember to reset USE_WINHANDLE back to 0 first:
Let>USE_WINHANDLE=0
Let>USE_WINHANDLE=0
MJT Net Support
[email protected]
[email protected]