This is probably an easy question. I think I'm overlooking something obvious.
I need to move the focus from a Macro Scheduler Pro (MSP) dialog to an already-open program called VueScan. I have no problem using the SetFocus command by itself:
Rem>Sends focus to VueScan.
SetFocus>VueScan*
The above works fine. However, when I try to use this with a MSP dialog, it doesn't work. It's supposed to send the focus to VueScan when the user pushes the command button:
Dialog>Dialog1
Caption=Dialog1
Width=445
Height=250
Top=111
Left=16
Button=Go to VueScan,152,48,121,25,1
EndDialog>Dialog1
Show>Dialog1
Label>lblCommandButtonPushed
Wait>0.5
GetDialogAction>Dialog1,strDialogResult
If>strDialogResult=1
Rem>Sends focus to VueScan.
SetFocus>VueScan*
Endif
Goto>lblCommandButtonPushed
Again, the above didn't work; to the user, it appears to do nothing. I thought that maybe the focus did move to VueScan, but it came back to my macro so fast that I missed it. So I tried this (only changes to the above are the "Wait>15" and the MessageModal lines):
Dialog>Dialog1
Caption=Dialog1
Width=445
Height=250
Top=111
Left=16
Button=Go to VueScan,152,48,121,25,1
EndDialog>Dialog1
Show>Dialog1
Label>lblCommandButtonPushed
Wait>0.5
GetDialogAction>Dialog1,strDialogResult
If>strDialogResult=1
Rem>Sends focus to VueScan.
SetFocus>VueScan*
Wait>15
MessageModal>15 seconds is up.
Endif
Goto>lblCommandButtonPushed
What happens, using the above code, when the user pushes the command button is that there is a 15 second pause; then a messagebox appears with my "15 seconds is up" message. VueScan never comes to the foreground.
I also tried adding to the above code "WaitWindowOpen>VueScan*" (sans quotes) either 1 line before or after "SetFocus>VueScan*". Neither of these had any apparent effect.
Incidentally, I'm using MSP ver. 7.4.008.
HELP!!!!!!!!!!!!!!!
Thanks much.
Send focus to another open program from dialog
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 9
- Joined: Tue May 02, 2006 7:13 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
The SetFocus line is finding the button on your dialog.
Try this instead:
Dialog>Dialog1
Caption=Dialog1
Width=445
Height=250
Top=111
Left=16
Button=Go to VueScan,152,48,121,25,1
EndDialog>Dialog1
Show>Dialog1
Label>lblCommandButtonPushed
Wait>0.5
GetDialogAction>Dialog1,strDialogResult
If>strDialogResult=1
Rem>Sends focus to VueScan.
Let>WF_TYPE=0
SetFocus>VueScan*
Endif
Wait>0.2
Goto>lblCommandButtonPushed
I have also added a Wait>0.2 inside the action loop to ensure the loop doesn't block the processor.
Try this instead:
Dialog>Dialog1
Caption=Dialog1
Width=445
Height=250
Top=111
Left=16
Button=Go to VueScan,152,48,121,25,1
EndDialog>Dialog1
Show>Dialog1
Label>lblCommandButtonPushed
Wait>0.5
GetDialogAction>Dialog1,strDialogResult
If>strDialogResult=1
Rem>Sends focus to VueScan.
Let>WF_TYPE=0
SetFocus>VueScan*
Endif
Wait>0.2
Goto>lblCommandButtonPushed
I have also added a Wait>0.2 inside the action loop to ensure the loop doesn't block the processor.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 9
- Joined: Tue May 02, 2006 7:13 pm
Thanks
Dear mtettmar:
Wow, you got back to me fast! I'm impressed! I'll try your suggestion.
By the way, I think your "Wait>0.2" is redundant. I already put the "Wait>0.5" in there to keep the loop from hogging all the CPU time.
Again, thanks so much for the speedy response! I'll try your suggestion.
--Eric
Wow, you got back to me fast! I'm impressed! I'll try your suggestion.
By the way, I think your "Wait>0.2" is redundant. I already put the "Wait>0.5" in there to keep the loop from hogging all the CPU time.
Again, thanks so much for the speedy response! I'll try your suggestion.
--Eric
-
- Newbie
- Posts: 9
- Joined: Tue May 02, 2006 7:13 pm
It works but why
Dear mtettmar:
You're a genius! (It worked.)
Now my question is: Why did it work?
I NEVER would have figured this trick out from the MSP documentation. The "WF_TYPE=0" that solved the problem is supposed to prevent SetFocus from affecting child windows. I guess that my dialog is considered a child window. However, if it is, it's a child window that doesn't contain the string "VueScan" anywhere in its title.
"SetFocus>VueScan*" should only affect windows with "VueScan" in the title (more precisely, STARTING the title), right? Have I discovered a bug (logic error) in MSP, or am I overlooking something?
Thanks again for the solution and for the speedy response.
--Eric
You're a genius! (It worked.)
Now my question is: Why did it work?
I NEVER would have figured this trick out from the MSP documentation. The "WF_TYPE=0" that solved the problem is supposed to prevent SetFocus from affecting child windows. I guess that my dialog is considered a child window. However, if it is, it's a child window that doesn't contain the string "VueScan" anywhere in its title.
"SetFocus>VueScan*" should only affect windows with "VueScan" in the title (more precisely, STARTING the title), right? Have I discovered a bug (logic error) in MSP, or am I overlooking something?
Thanks again for the solution and for the speedy response.
--Eric
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
The SetFocus line was focusing the BUTTON on your dialog, NOT your dialog. The button is a child of the dialog. So setting WF_TYPE to do main windows only (no child windows) means it won't find the button.
You have not discovered a bug. SetFocus>VueScan* will find any window whose caption *contains* the word VueScan.
It was easy to determine what the problem was. If no such window is found you will get a warning message and the chance to continue or abort the script. If no warning message then IT MUST HAVE FOUND A MATCHING WINDOW. So the conclusion when I ran your script is "it is finding a window, just not the one you want it to find, therefore, we need to ensure the SetFocus line is narrowed down a bit more to find only the window you want it to find". As it happened, in my case, the window it was finding was a button in the dialog. I have no other windows on my system with VueScan in the title. When I added WF_TYPE=0 I got the warning that it couldn't find a VueScan window, which is what I would expect.
You have not discovered a bug. SetFocus>VueScan* will find any window whose caption *contains* the word VueScan.
It was easy to determine what the problem was. If no such window is found you will get a warning message and the chance to continue or abort the script. If no warning message then IT MUST HAVE FOUND A MATCHING WINDOW. So the conclusion when I ran your script is "it is finding a window, just not the one you want it to find, therefore, we need to ensure the SetFocus line is narrowed down a bit more to find only the window you want it to find". As it happened, in my case, the window it was finding was a button in the dialog. I have no other windows on my system with VueScan in the title. When I added WF_TYPE=0 I got the warning that it couldn't find a VueScan window, which is what I would expect.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 9
- Joined: Tue May 02, 2006 7:13 pm
Thanks mtettmar
Dear mtettmar:
Wow, what a clear (and again timely) explanation! Once more, I'm really impressed.
Thanks so much for your help!
(No need to waste your time responding to this post.)
--Eric
Wow, what a clear (and again timely) explanation! Once more, I'm really impressed.
Thanks so much for your help!
(No need to waste your time responding to this post.)
--Eric