GetActiveWindow and dialog button questions

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

GetActiveWindow and dialog button questions

Post by JRL » Fri Feb 08, 2008 5:24 pm

A couple of quick questions.

When running the following, I cannot get info about Button1. If I select Button1, should it not become the focused child window and therefore be the target for GetActiveWindow> while GAW_TYPE=1?

I'm also confused why the "Title" variable in the GetActiveWindow> function is not being set to the button's handle. I have WIN_USEHANDLE set to 1.

Macro Scheduler version 10.019
Windows XP

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=445
   Height=250
   Top=163
   Left=27
   Button=Button1,220,100,105,55,3
   Button=Button2,80,100,75,25,4
   Label= ,125,20,true
   Label= ,125,40,true
   Label= ,125,60,true
EndDialog>Dialog1

Show>dialog1

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

Label>EOF

SRT>Process
  Let>WIN_USEHANDLE=1
  Let>GAW_TYPE=1
  GetActiveWindow>Title,ButtonX,ButtonY,ButtonW,ButtonH
  Let>dialog1.mslabel1=Button X,Y Coordinate = %ButtonX%,%ButtonY%
  Let>dialog1.mslabel2=Button W,H Dimension = %ButtonW%,%ButtonH%
  Let>dialog1.mslabel3=Button Title = %Title%
  Let>WIN_USEHANDLE=0
  Let>GAW_TYPE=0
  ResetDialogAction>dialog1
END>Process

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

Post by JRL » Sun Feb 10, 2008 1:21 am

I still don't know why the script in the first post doesn't work but I found a way to get the info I want by adding a setfocus> to the button handle line.

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=445
   Height=250
   Top=163
   Left=27
   Button=Button1,220,100,105,55,3
   Button=Button2,80,100,75,25,4
   Label= ,125,20,true
   Label= ,125,40,true
   Label= ,125,60,true
EndDialog>Dialog1

Show>dialog1

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

Label>EOF

SRT>Process
  Let>WIN_USEHANDLE=1
  Sub>res1,2
  SetFocus>dialog1.msbutton%res1%.handle
  Let>WIN_USEHANDLE=0
  Let>GAW_TYPE=1
  GetActiveWindow>Title,ButtonX,ButtonY,ButtonW,ButtonH
  Let>dialog1.mslabel1=Button X,Y Coordinate = %ButtonX%,%ButtonY%
  Let>dialog1.mslabel2=Button W,H Dimension = %ButtonW%,%ButtonH%
  Let>dialog1.mslabel3=Button Title = %Title%
  Let>GAW_TYPE=0
  ResetDialogAction>dialog1
END>Process

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

Post by Marcus Tettmar » Sun Feb 10, 2008 7:04 pm

Hmmm .. I wouldn't nowmally expect GetActiveWindow to return a button - probably getting the window that owns/contains the button. But it'll probably vary from app to app. But then I guess SetFocus is forcing it to become the active window.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Sun Feb 10, 2008 11:27 pm

Once you have the button's handle, GetWindowPos> does well to get a button location. Any thought about a GetWindowSize> that would work like GetWindowPos>? Although at the moment GetActiveWindow> seems to be working its just that it appears the button needs to be focused for it to work.

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