Custom Dialog / Setfocus issue

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Custom Dialog / Setfocus issue

Post by jbas » Thu Dec 30, 2010 5:31 pm

My script opens an application window and then displays a custom dialog box with information about the changes that need to be made in that window. The changes needed in the application window are too complex to automate at this time. The custom dialog window has 'proceed' and 'cancel' buttons for the user to select after they have completed their changes.

The problem I am having is, that after the user makes changes in the application window and presses the 'Proceed' button, Macro Scheduler is unable to Setfocus on the application window to close it and reopen the application window for the next account.

If the user makes no changes in the application window but just presses 'Proceed' in the custom dialog window for each account the problem does not occur.

Also, if I put a long pause in the script after the 'Proceed' button is pressed and manually click in the application window so it has 'focus' before the script continues it runs without problem.

I am using window 'handles' for my processing (WIN_USEHANDLE=1)

Any ideas on why the Setfocus command is not working?

jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Post by jbas » Thu Dec 30, 2010 6:21 pm

I also do not have the problem if I use the 'ask' function. As a workaround, is there any way to specify the screen location of the 'Ask' function?

Doesn't this indicate that the problem might be with the Dialog?

The dialog is as follows:
Dialog>CER_FindOrd_Dialog1
object CER_FindOrd_Dialog1: TForm
Left = 247
Top = 96
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 86
ClientWidth = 372
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 8
Width = 32
Height = 13
Caption = 'Label1'
end
object Label2: TLabel
Left = 8
Top = 32
Width = 286
Height = 13
Caption = 'Select the appropriate row in Cerner and then click '#39'Proceed'#39
end
object MSButton1: tMSButton
Left = 7
Top = 55
Width = 75
Height = 25
Caption = 'Proceed'
DoubleBuffered = True
ModalResult = 1
ParentDoubleBuffered = False
TabOrder = 0
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 87
Top = 54
Width = 75
Height = 25
Caption = 'Cancel'
DoubleBuffered = True
ModalResult = 2
ParentDoubleBuffered = False
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>CER_FindOrd_Dialog1

The code I run to call the dialog is as follows:
Let>Msg_Out=%XL_Nm%; %XL_ORD_Dt%; %XL_AccNbr%; %XL_ORD_Nm%
SetDialogProperty>CER_FindOrd_Dialog1,,Left,850
SetDialogProperty>CER_FindOrd_Dialog1,,Top,70
SetDialogProperty>CER_FindOrd_Dialog1,Label1,Caption,Msg_Out
Show>CER_FindOrd_Dialog1,CER_FindOrd_Dialog1_Rslt
If>CER_FindOrd_Dialog1_RsltMain_Exit
Goto>CFO_Exit
Endif

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

Post by JRL » Thu Dec 30, 2010 10:41 pm

I don't know what might be causing your problem. I doubt that it's the dialog itself but stranger things have happened.

As you requested, here is a potential workaround with Ask>.

Code: Select all

Let>NewX=200
Let>NewY=100
Let>TempScript=%temp_dir%Temp~Move~Ask~Window.scp

WriteLn>TempScript,wres,WaitWindowOpen>Confirm
WriteLn>TempScript,wres,MoveWindow>Confirm,%NewX%,%NewY%
WriteLn>TempScript,wres,DeleteFile>%TempScript%

ExecuteFile>%TempScript%

Ask>test,res

jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Post by jbas » Fri Dec 31, 2010 1:07 am

I love the solution - very clever!

I set up MvAsk.scp as a 'permanent' rather than 'temporary' script and then ran the following code:

ExecuteFile>C:\Users\[usernm]\Documents\Macro Scheduler 12\MvAsk.scp
Ask>Msg_Out,AskResponse
If>%AskResponse%=NO
SkipLabel>Main_Exit
Goto>CFO_Exit
Endif
SetFocus>WinTile_Handle
Wait>5.00

With the 'ExecuteFile' statement uncommented the 'Confirm' window appears and gets moved - but the SetFocus doesn't work.

If I comment out the 'ExecuteFile' statement the script runs as expected - the 'Confirm' window just gets covered by the application window and has to be found again to continue.

jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Post by jbas » Fri Dec 31, 2010 3:29 am

I add the following statements after the 'Wait>5.00' statement shown in my previous message.

GetActiveWindow>tst_title,tst_X,tst_Y,tst_W,tst_H
**breakpoint**

tst_title is equal to WinTitle_Handle, as if SetFocus worked. But on the screen itself, the window associated with WinTitle_Handle never obtains focus.

jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Post by jbas » Fri Dec 31, 2010 4:21 am

A 'MoveMouseRel' followed by a 'LClick' will be my work-around until I find out why SetFocus doesn't work in this instance.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 31, 2010 3:02 pm

Impossible for us to say without seeing/debugging your script as we only have snippets of it to go on. But I note you are setting focus to something contained in WinTileHandle but in your message you refer to WinTiTleHandle emphasis mine. They're not the same.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Post by jbas » Sat Jan 01, 2011 2:40 am

Thank-you Marcus - the misspelling of WinTitle_Handle was the issue.
It is truly amazing that I could not see that!

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