SetFocus to Non-MacSched Window Objects

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

SetFocus to Non-MacSched Window Objects

Post by JRL » Thu Jul 18, 2013 5:56 pm

I want to be able to set focus to Window objects using their handle. The following script demonstrates. It opens the Internet Properties window, moves and resizes the "Cancel" button, Then sets focus to the "Cancel button. All of this works in Windows 7. Only the move and resize work in Windows XP.

Reading about the Windows API SetFocus function on the MSDN website they state.
MSDN wrote:The window must be attached to the calling thread's message queue
Since the Macro Scheduler SetFocus function can set focus to any window I've ever used it on, I'm assuming that there is something in the function that performs this message queue attachment. And since I can set focus to Window objects in Win7, I'm wondering if there is some message queue attachment disconnect in WinXP. Is there any libfunc that can make this work in WinXP? Or does any one know of some other method to set focus to a Window object other than using the mouse or keyboard?




Code: Select all

ExecuteFile>InetCPL.cpl
WaitWindowOpen>Internet Properties
wait>0.5

GetWindowHandle>Internet Properties,hwnd
Let>WIN_USEHANDLE=1
  GetWindowChildList>hwnd,hwnd_list
Let>WIN_USEHANDLE=0

Separate>hwnd_List,crlf,handle

Let>WIN_USEHANDLE=1
  MoveWindow>Handle_26,100,100
  ResizeWindow>Handle_26,100,100
  SetFocus>Handle_26
Let>WIN_USEHANDLE=0

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 19, 2013 4:30 am

Just tried this on my Win 7 pro at home and it does not set focus on the "Cancel" button. Same issue I'm having with my Win Xp at work. Now I'm even more confused

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Jul 19, 2013 12:43 pm

It works for me but only when I move the mouse over the Cancel button.

Code: Select all

ExecuteFile>InetCPL.cpl
WaitWindowOpen>Internet Properties
Wait>0.5

GetWindowHandle>Internet Properties,hwnd
Let>WIN_USEHANDLE=1
  GetWindowChildList>hwnd,hwnd_list
Let>WIN_USEHANDLE=0

Separate>hwnd_List,crlf,handle

Let>WIN_USEHANDLE=1
  MoveWindow>Handle_26,100,100
  ResizeWindow>Handle_26,100,100
  SetFocus>Handle_26
  GetCursorPos>x,y
  MouseOver>Internet Properties,Cancel
  Wait>0.1
  MouseMove>x,y
Let>WIN_USEHANDLE=0

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Jul 19, 2013 12:45 pm

I take that back, it's not setting focus to the Cancel button.

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 19, 2013 1:14 pm

Rain, is this a Win 7 computer you tried the script on?

Thanks. I was about to ask you if it was really getting focus or if the mouseover> is just making the cancel button display. For what ever reason moving the button makes the button disappear until the mouse runs over the top of its position then it appears. That's kind of weird but I don't really care about that. In my production script I'm not moving or resizing buttons, I just wanted to demonstrate that you can move them and resize them but can't set focus to them... Except on my one win7 machine.

I don't understand that either. Its a 64 bit Win 7 pro Dell Optiplex with nothing fancy installed and is almost identical to my home computer which is also a 64 bit Win 7 pro Dell Optiplex with nothing fancy installed. The home computer is about a year newer so I'm sure they are not identical. Probably some driver that installed its own version of some dll that is allowing Macro Scheduler's SetFocus> function to set focus to window objects on the work computer.

I hate computers.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Jul 19, 2013 1:19 pm

Windows 7 Ultimate.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Jul 19, 2013 4:23 pm

What about this?

Code: Select all

ExecuteFile>InetCPL.cpl
WaitWindowOpen>Internet Properties
Wait>0.5

GetWindowHandle>Internet Properties,hwnd
Let>WIN_USEHANDLE=1
  GetWindowChildList>hwnd,hwnd_list
Let>WIN_USEHANDLE=0

Separate>hwnd_List,crlf,handle

Let>WIN_USEHANDLE=1
  MoveWindow>Handle_26,100,100
  ResizeWindow>Handle_26,100,100
  Press Tab *14
Let>WIN_USEHANDLE=0

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 19, 2013 7:09 pm

Thanks Rain. But as I mentioned in the first post, I want to set focus without using mouse or keyboard emulation. I didn't say emulation before thinking it was implied.

I have a working script using mouse move and left click to set focus to the edit boxes in Global Shop (ERP software).

Global Shop is written in Cobol and the dialogs do not behave exactly as normal Windows dialogs behave. I have found, for example, that I can fill out all the edit boxes of a dialog using SetControlText and everything looks good, but when you press the Ok button the dialog doesn't recognize that anything has been entered. You get an error that is identical to the error you get if you press Ok without filling in any edit boxes.

When Marcus came out with ObjectSendText> I was excited to try it but got the same result as with SetControlText>. This week I discovered that if I first set focus to the edit box, use ObjectSendText> to populate the edit box, then press tab to leave the edit box. I get 100% reliability with very rapid input.

What I'm hoping for is to get away from the mouse moves, not because they don't work but because they add complexity, inconvenience and may also contribute to unreliability for scripts that are to be run on users computers. you can use blockinput to help assure reliability but that adds even more complexity to the script. Complexity is important because every Global Shop update (about every three months) there is a probability of script rewrites due to changes in the dialogs. As time goes by I have more and more scripts to test and or rewrite.

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