Problem with SetFocus after ResetDialogAction

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
DrPain
Newbie
Posts: 10
Joined: Sun Mar 26, 2006 2:38 pm

Problem with SetFocus after ResetDialogAction

Post by DrPain » Tue Jan 29, 2008 7:06 pm

Is there some reason why SetFocus won't work some time after calling ResetDialogAction?

I find that it does work when setting focus to a "normal" window's app, such as Calculator, however it does not work to set focus to a windowed DirectX program.

If I remove the call to ResetDialogAction, SetFocus then works fine. Of course then I can't interact with the dialog box.

I've tried using the window name as well as the handle (changing the value of WIN_USEHANDLE appropriately) with the same results.

I'd post a sample app, but my macro is almost 3000 lines long, and the test I wrote won't break, so perhaps there is some other interaction/bug going on.

Any ideas?

DrPain
Newbie
Posts: 10
Joined: Sun Mar 26, 2006 2:38 pm

Post by DrPain » Wed Jan 30, 2008 3:23 am

More info: if I leave the DirectX app's window title alone, it works fine.
However it breaks when I change the title via the call:

LibFunc>User32,SetWindowTextA,r,hwnd,NewTitle

No error is thrown by SetFocus, so it is finding the window, it's just not bringing it to the front. Also, it does work when the ResetDialogAction function is not used.

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

Post by JRL » Wed Jan 30, 2008 4:36 am

I'm not sure how to resolve your problem but your last post reminded me of a phenomenon I noticed a while back. It appears that changing a dialog title using SetWindowTextA will only change the visible dialog title, it doesn't change the originally defined dialog. So resetting the dialog by using ResetDialogAction> will return the original title.

The following script will demonstrate. Pick the Change button and the dialog title will change. After a one second wait the script will execute a ResetDialogAction> and the original title will reappear.

Dialog>Dialog1
Caption=Original Title
Width=225
Height=130
Top=CENTER
Left=CENTER
Button=Change,72,56,75,25,3
EndDialog>Dialog1

Show>dialog1

Label>Loop
GetDialogAction>dialog1,res1
If>res1=2,EOF
If>res1=3,ChangeName
Wait>0.01
Goto>Loop

SRT>ChangeName
LibFunc>User32,SetWindowTextA,r,dialog1.handle,New Title
Wait>1
RDA>dialog1
END>ChangeName

Label>EOF

DrPain
Newbie
Posts: 10
Joined: Sun Mar 26, 2006 2:38 pm

Post by DrPain » Wed Jan 30, 2008 2:30 pm

Thanks JRL.

I have gotten it working now if I use the window handles. I had been using GetWindowHandle, which didn't work. If I tried to get the handle BEFORE changing the title, there would be multiple windows with the same title and who knows which window would be retrieved. If I got the handle AFTER changing the title, I guess this is just broken as you mention. So, I switched to using GetActiveWindow and that works fine.

I can change the title of the window after retrieving the handle and it works, so this is fine.

Don't know why using the window titles themselves don't work, probably the same issue you mention.

Anyway, it's all good now. :)

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