How can I SetFocus to one of my Dialog boxes?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

How can I SetFocus to one of my Dialog boxes?

Post by HPROS » Mon Dec 06, 2004 12:54 pm

I use Dialogs as Main Menu's in some of my scripts, and at times it would be helpful if I could Setfocus to a Dialog that is up, and pass commands to it as I would any other window. I tried the obvious "Setfocus>Dialogabc*" where the Dialogabc is the name of the Dialog, however it doesn't work. It is odd as even when the window is "focused" I can't pass commands to it via my script, but manually if I hit them the cursor responds properly.

Thanks!

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

Post by support » Mon Dec 06, 2004 1:16 pm

Um, clearly it is impossible to focus a modal dialog from the script that displayed it because the script is waiting for the dialog to close before it can do anything else. I would have though this was obvious. If not read my recent explanation of what modal means in this forum. Modal forms halt execution until they are closed. So while a modal form is displayed the process that displayed it does nothing.

However:
- You should be able to focus a non-modal dialog from within the same script since the script is executing while the dialog is showing.
- It is possible that another application/macro scheduler instance could focus the dialog by focusing the application that owns it (macro scheduler).
MJT Net Support
[email protected]

Guest

similar question...

Post by Guest » Mon Dec 06, 2004 2:08 pm

Hello, this sounds kind of similar to my question, support helped/gave me a Setfocus to IE Explorer then using a number of Press Tab to get to a specified ID box to enter a number. This works fine unless the target computer has more or less search windows in the browser.

It’s not a big deal for me to compile a few of these with more or less Press Tabs in it but if the target computer ever adds or subtracts a search window like Google I’ll have to go back and change the Macro.

My question is, can I get to that box by using its name?

Shel

And as always many thanks to the great support staff!

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Mon Dec 06, 2004 2:14 pm

Thank you for the info!

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Thu Dec 09, 2004 12:35 pm

If I compile two executables, one that creates a dialog (Modal) called "Menu", and launch another Macro executable called "locate" to setfocus on the Modal Window "Menu" according to your reply above this should work, however I still can not setfocus on the "Menu" window, and I have tried using "Macro Scheduler*" and "Menu*" etc. Please advise - thank you. If you have info on this I will read it, or an example that would be great. Thank you.

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Thu Dec 09, 2004 12:35 pm

Sorry - double post...

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

Post by support » Fri Dec 10, 2004 9:04 am

Works for me. Here's what I did.

1. I started the Dialog Example sample script.
2. I started another instance of Macro Scheduler.
3. I made a script that looked like this:

SetFocus>This is My Dialog
Press ALT
Press F4
Release ALT

4. Run that script and it closed the dialog in the first script.

This would be the same as running two compiled macros.
MJT Net Support
[email protected]

Guest

Post by Guest » Fri Dec 10, 2004 7:16 pm

Thank you for the prompt reply. I can do what you are doing, however my problem is that (using your example) I would want to be able to run the inital macro "dialog Example" and have it launch/"run" a separate executable from the initial macro (call it "control") that starts just BEFORE the message modal comes up, so when the "This is My Dialog" modal window is up the "control" executable can "setfocus" and tab to the field that I want in preparation for data entry to the "This is My Dialog" modal window again by the user.

The objective is to reset the cursor to the initial field in my dialog always. If you don't then the cursor is where you last left it in the dialog the next time the "show" command is executed which is sloppy.

What happens is the "setfocus" works but control never passes back to the user and the program hangs up and I have to "exit" out of macro Scheduler altogether.

Thank you for your help.

HPROS
Junior Coder
Posts: 35
Joined: Tue Sep 16, 2003 7:52 pm
Location: Columbia, CT
Contact:

Post by HPROS » Fri Dec 10, 2004 7:20 pm

Sorry - that last post was from Hpros....

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

Post by support » Fri Dec 10, 2004 7:22 pm

That won't work because if the second macro is launched by the first then it is owned by the first and is therefore part of the same process. Therefore the modal dialog belongs to it - they are all part of the same process - and the dialog is modal to the process - the process thread is suspended until the dialog is closed.

Maybe one workaround - launch the second macro via a desktop shortcut hotkey or by sending a double click on the shortcut. That way the process is independent as it is started by Windows.
MJT Net Support
[email protected]

Guest

Post by Guest » Fri Dec 10, 2004 7:28 pm

Thank you for the qick reply, at least I am not completely crazy. I researched for any similar writeups, and then tested it every way I could think of, before finally posting the question. Issue closed.

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