Control First Field/Object during Dialog reuse/loop

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
MikeB941
Newbie
Posts: 17
Joined: Sat Jul 07, 2007 7:53 pm

Control First Field/Object during Dialog reuse/loop

Post by MikeB941 » Thu Sep 06, 2007 8:04 am

Hello - I'm reusing a modal dialog inside a loop with resetdialogaction.

The first time the dialog is executed the cursor begins in the first field/object as expected based on the order of objects in the dialog.

From the second pass onward, the cursor starts off in whatever the LAST field/object that was entered at the time the OK button was pressed in the PREVIOUS iteration.

Is there any way to reset or force the cursor back to the first field/object in the dialog on each modal pass?

Thanks a million for any help.

Take Care... Mike.

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

Post by Marcus Tettmar » Thu Sep 06, 2007 9:21 am

Do this:

LibFunc>User32,SetFocus,r,Dialog1.msEdit1.Handle

Replace Dialog1.msEdit1.Handle with the handle variable for the object in question.

If you debug step past your Dialog> block you'll notice in the watch list that a number of variables are created all ending in .HANDLE. These variables store the handle of each of the objects. E.g.

Dialog1.Handle
Dialog1.msButton0.Handle
Dialog1.MyEdit.Handle

etc.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

MikeB941
Newbie
Posts: 17
Joined: Sat Jul 07, 2007 7:53 pm

Post by MikeB941 » Thu Sep 06, 2007 3:45 pm

Hi Marcus!

Thanks for this - it works great on the SECOND pass (the cursor is positioned in the first object of the dialog as expected), but on the third pass the dialog "locks up". It's not in a loop (I checked the windows task manager), but it will only accept 1 character really quickly and the locks out all other keyboard entry (including shift-esc - I have to kill the msched task from the windows task manager).

This is the first time I've directly used the user32 lib in any script.

Thanks again for any help!

Take Care... Mike.

MikeB941
Newbie
Posts: 17
Joined: Sat Jul 07, 2007 7:53 pm

Post by MikeB941 » Thu Sep 06, 2007 4:03 pm

Just also wanted to mention that I added a call to user32,SetWindowTextA to change the text of the dialog window and that works great! It's only the setfocus I'm still having trouble with.

Thanks again!

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

Post by JRL » Thu Sep 06, 2007 10:31 pm

Hi Mike,

I wrote a little script that confirmed your issue. Tried lots of things to make this work and finally added a show>dialog1 ahead of the libfunc> and a closedialog>dialog1 immediately following so that the dialog is actually open when the setfocus takes place and that seemed to eliminate the lockup. This may not actually resolve the issue but it seems to be a way to get around it.

Hope this helps,
Dick

Code: Select all


Dialog>Dialog1
   Caption=Object focus test
   Width=327
   Height=126
   Top=104
   Left=16
   Edit=msEdit1,16,8,281,
   CheckBox=msCheckBox1,Enable Edit Object focus,80,40,153,True
   Button=OK,116,64,75,25,3
EndDialog>Dialog1

Label>Loop
Show>dialog1,res1
Closedialog>dialog1
Wait>.2
If>res1=2,EOF
If>%dialog1.mscheckbox1%=True
  //remark out the following line and the closedialog> line and the
  //script will lock up the second time through.
  Show>dialog1
  LibFunc>User32,SetFocus,focres,Dialog1.msEdit1.Handle
  Closedialog>dialog1
EndIf
//For some reason this Messagemodal> line will also prevent a lockup
//MDL>returned %focres%
Wait>.2
Let>res1=
Goto>Loop
Label>EOF

MikeB941
Newbie
Posts: 17
Joined: Sat Jul 07, 2007 7:53 pm

Post by MikeB941 » Fri Sep 07, 2007 7:34 am

Thanks a million Dick!

This solved the problem!

Take Care... Mike.

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