I have a button that has different states and captions.
I'd like to not have to worry about the resolution of the application.
I need to know if the button has the right text AND if the button is enabled.
Currently I'm waiting for the pixel color of some text to turn black indicating that the button is now active then I proceed with the macro.
The pixel color works great but is very dependant on resolution and position. I'm looking for a better solution that removes these dependancies.
Here's what I'm working with.
Button states--------Caption------Action
-------------------------------------------------------------
Disabled---------&Take Call------Wait for call to come in
Active------------&Take Call------Click and answer incoming call
Active------------&End Call-------Click to End call OR wait/run other tests
Any ideas would be greatly appreciated.
Would like to avoid using FindImage or WaitPixelColor...
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Getting the caption should be easy - just use GetControlText.
To determine if the button is enabled or not use the IsWindowEnabled API function:
Above example gets the handle of a window called "Options". Then gets the handle of the "TButton" object with caption "&OK" on that window. Then passes that to IsWindowEnabled to see if it is enabled or not.
To determine if the button is enabled or not use the IsWindowEnabled API function:
Code: Select all
//Get handle of Options window
GetWindowHandle>Options,hwnd
//Find the handle of the &OK Button (TButton in this case) object
LibFunc>User32,FindWindowExA,btnWnd,hwnd,0,TButton,&OK
//Is Button Enabled
LibFunc>User32,IsWindowEnabled,IsEnabled,btnWnd
If>IsEnabled=1
MessageModal>Button Enabled
Else
MessageModal>Button Disabled
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Ack... Still having issues. Not getting the right handle.
Still not working... here is my code. I've included the related debug return codes in the comments.
Looks like the problem is that the FindWindowExA is just returning the parent window handle...
Sorry for being a noob... I'm sure it's something simple that I'm missing.
//Set Focus
SetFocus>A Station
//Get handle of Options window
GetWindowHandle>A Station,hwndAStation
//Returns hwndAgentStation=2163180
//Is Take call available?
GetControlText>A Station,WindowsForms10.BUTTON.app.0.378734a,1,buttontext1
If>buttontext1=&Take Call
//Find the handle of the &Take Call Button (TButton in this case) object
LibFunc>User32,FindWindowExA,btnTakeCallWnd,hwndAStation,0,WindowsForms10.BUTTON.app.0.378734,&Take Call
/* This returns the following:
BTNTAKECALLWND=0
BTNTAKECALLWND_1=2163180
BTNTAKECALLWND_2=0
BTNTAKECALLWND_3=WindowsForms10.BUTTON.app.0.378734 (I've also tried TButton)
BTNTAKECALLWND_4=&Tall
*/
//Is Button Enabled
LibFunc>User32,IsWindowEnabled,IsEnabled,btnTallWnd
//Returns
//ISENABLED=0
//ISENABLED_1=0
If>IsEnabled=1
MessageModal>Button Enabled %buttontext1%
//Add code to take the call
Else
MessageModal>Button Disabled %buttontext1%
//Loop back and wait for button to be enabled.
Endif
Else
MessageModal>Button is "End Call"
//Loop back and wait for button to be enabled.
Endif
Looks like the problem is that the FindWindowExA is just returning the parent window handle...
Sorry for being a noob... I'm sure it's something simple that I'm missing.
Last edited by aux_con on Wed Jan 03, 2007 12:04 am, edited 1 time in total.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Is the button a direct child of the window or is there an extra step(s) in the hierarchy. Use Tools/View System Windows to view the tree. The button may have a parent which is a child of the window, and we therefore need additional FindWindowEx calls. Feel free to provide a screen shot of your View System windows tree.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Looks like 2 layers are involved here...
//Find the handle of the Take Call Button
//Get left pane handle (child of main window)
LibFunc>User32,FindWindowExA,leftPaneWnd,hwndAStation,0,WindowsForms10.Window.8.app.0.378734a,
//Get button handle (child of left pane)
LibFunc>User32,FindWindowExA,btnTakeCallWnd,leftPaneWnd,0,0,&all
The weird part of this is that I could not see the leftpane handle in the tree with the built in tool... I used SPY++ and then I was able to see that the target was indeed a child of the leftpane control.
Thanks for the great tip!
(btw My test team is loving this tool... Kudos!)
//Find the handle of the Take Call Button
//Get left pane handle (child of main window)
LibFunc>User32,FindWindowExA,leftPaneWnd,hwndAStation,0,WindowsForms10.Window.8.app.0.378734a,
//Get button handle (child of left pane)
LibFunc>User32,FindWindowExA,btnTakeCallWnd,leftPaneWnd,0,0,&all
The weird part of this is that I could not see the leftpane handle in the tree with the built in tool... I used SPY++ and then I was able to see that the target was indeed a child of the leftpane control.
Thanks for the great tip!
(btw My test team is loving this tool... Kudos!)