Sign in to follow this  
Followers 0
codeninja

Get the information about selected control

26 posts in this topic

Hi,

How can i get the information about the selected control in windows form?

Thanks,

--SJ

Share this post


Link to post
Share on other sites



codeninja,

If the control accepts keyboard input then you could try _WinAPI_GetFocus. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Melba,

It returns 0x0...0 probably it means failure. FYI, My control is located inside the infragistics grid-view control.(By using window info i could not identify its name because it present inside the grid-view)

I attached the sample grid view of mine. in this grid i can select total combo-box but i can't modify the selected item?

How can i modify the selected item of combo-box?

Thanks,

--SJ

codeninja,

If the control accepts keyboard input then you could try _WinAPI_GetFocus. :)

M23

post-84013-0-78659600-1387453758_thumb.p

Edited by codeninja

Share this post


Link to post
Share on other sites

codeninja,

It sounds as if that control is user-drawn and so not accessible via the Windows API. Hence Autoit will not be able to automate it using the standard functions. :(

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for your support,

and one more question is,

I can read the text-box value by sending ctrl+c key stroke inside the grid and i would like to read combo-box selected item too.

How can i read the selected item from the combo-box which is present inside the same grid-view? is their any key board short cut to do this?

--SJ

Edited by codeninja

Share this post


Link to post
Share on other sites

are you able to focus on the combo box, as discussed in previous thread?

'?do=embed' frameborder='0' data-embedContent>>

if so, and if the combo box behaves as a combo box should behave, then by sending down arrow you would open the drop-down list, then by sending some more arrows and Enter will change the value. or better still, if you know what you want to put in, just send the string, it shoudl even auto-complete as you "type".

1 person likes this

Share this post


Link to post
Share on other sites

Thanks for your support,

and one more question is,

I can read the text-box value by sending ctrl+c key stroke inside the grid and i would like to read combo-box selected item too.

How can i read the selected item from the combo-box which is present inside the same grid-view? is their any key board short cut to do this?

--SJ

 

if the combo box is not read-only then Ctrl+C will do it. otherwise it requires some extra thinking...

1 person likes this

Share this post


Link to post
Share on other sites

Hi orbs,

I can select combo-box control inside the grid-view by implementing mouse click based on grid-view co-ordinates.

Now, i would like to read the selected text of combo-box? do you know any short cut keys to perform this action.

Thanks 

--SJ

Share this post


Link to post
Share on other sites

does your combo box look like the 1st or the 2nd in this screenshot?

post-47848-0-47745000-1387455580_thumb.p

if it's like the 1st, then Ctrl+C should do it. otherwise it may be not possible, and i guess you'll have to ask yourself "do i really need to read the value? can i work without reading the value?"

1 person likes this

Share this post


Link to post
Share on other sites

does your combo box look like the 1st or the 2nd in this screenshot?

attachicon.gifcombo.png

if it's like the 1st, then Ctrl+C should do it. otherwise it may be not possible, and i guess you'll have to ask yourself "do i really need to read the value? can i work without reading the value?"

 

Thank You. I Agree

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Sometimes, you can luck out, and use the wrapping control as the parent (must be a handle) in the function:

WinGetClassList

example of use:

#include <Array.au3>
Func Var_GetAllWindowsControls($hCallersWindow)
    ; Get all list of controls
    $sClassList = WinGetClassList($hCallersWindow)

    ; Create array
    $aClassList = StringSplit($sClassList, @CRLF, 2)

    ; Sort array
    _ArraySort($aClassList)
    _ArrayDelete($aClassList, 0)

    ; Loop
    $iCurrentClass = ""
    $iCurrentCount = 1
    $iTotalCounter = 1

    For $i = 0 To UBound($aClassList) - 1
        If $aClassList[$i] = $iCurrentClass Then
            $iCurrentCount += 1
        Else
            $iCurrentClass = $aClassList[$i]
            $iCurrentCount = 1
        EndIf

        $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]")
        $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}")
        $aPos = ControlGetPos($hCallersWindow, "", $hControl)
        $sControlID = _WinAPI_GetDlgCtrlID($hControl)
        If IsArray($aPos) Then
            ConsoleWrite("Func=[Var_GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] Text=[" & $text & "]." & @CRLF)
        Else
            ConsoleWrite("Func=[Var_GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF)
        EndIf
        If Not WinExists($hCallersWindow) Then ExitLoop
        $iTotalCounter += 1
    Next

EndFunc   ;==>Var_GetAllWindowsControls
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

To automate these Infragistics controls you need the Microsoft UI Automation framework. You find an AutoIt implementation in this example.

From the Infragistics website here (search for "ui automation"):

"The Infragistics WPF suite of controls fully support Microsoft UI Automation. ...

Another key use of UI Automation is automated testing; the framework allows test scripts to access and interact with the UI elements."

1 person likes this

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

To automate these Infragistics controls you need the Microsoft UI Automation framework. You find an AutoIt implementation in this example.

From the Infragistics website here (search for "ui automation"):

"The Infragistics WPF suite of controls fully support Microsoft UI Automation. ...

Another key use of UI Automation is automated testing; the framework allows test scripts to access and interact with the UI elements."

Hi LarsJ,

 Thanks for your idea. Is this possible to integrate AutoIt script with MS UI Automation Framework? my question maybe weird but i don't know how to do this.

--SJ

Edited by codeninja

Share this post


Link to post
Share on other sites

 

Sometimes, you can luck out, and use the wrapping control as the parent (must be a handle) in the function:

WinGetClassList

example of use:

#include <Array.au3>
Func Var_GetAllWindowsControls($hCallersWindow)
    ; Get all list of controls
    $sClassList = WinGetClassList($hCallersWindow)

    ; Create array
    $aClassList = StringSplit($sClassList, @CRLF, 2)

    ; Sort array
    _ArraySort($aClassList)
    _ArrayDelete($aClassList, 0)

    ; Loop
    $iCurrentClass = ""
    $iCurrentCount = 1
    $iTotalCounter = 1

    For $i = 0 To UBound($aClassList) - 1
        If $aClassList[$i] = $iCurrentClass Then
            $iCurrentCount += 1
        Else
            $iCurrentClass = $aClassList[$i]
            $iCurrentCount = 1
        EndIf

        $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]")
        $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}")
        $aPos = ControlGetPos($hCallersWindow, "", $hControl)
        $sControlID = _WinAPI_GetDlgCtrlID($hControl)
        If IsArray($aPos) Then
            ConsoleWrite("Func=[Var_GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] Text=[" & $text & "]." & @CRLF)
        Else
            ConsoleWrite("Func=[Var_GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF)
        EndIf
        If Not WinExists($hCallersWindow) Then ExitLoop
        $iTotalCounter += 1
    Next

EndFunc   ;==>Var_GetAllWindowsControls

 

Hi jdelaney,

 I have tried this method but it does not return the controls which is present inside the infragistics grid-view.

--SJ

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

codeninja, Download the UDFs here and download and run the code in the "Simple spy demo" code box in the middle of the first post. Then click the Grid control (to set focus) and press Ctrl+w. You'll see info in the edit box.

To print all controls (including non-visible) in Scite console run the code in post 71.

You can also run the UISpy.exe (old) or Inspect.exe (new) tools from Microsoft. If you can get information with these tools you know that the controls can be handled with the Microsoft UI Automation framework.

Edited by LarsJ
1 person likes this

Share this post


Link to post
Share on other sites

Hi LarsJ

I get following information about the text box control which is present inside the infragistics grid-view

 

Mouse position is retrieved 478-419

At least we have an element [][WindowsForms10.EDIT.app.0.2780b98_r13_ad1]
Having the following values for all properties: 
Title is: <> Class   := <WindowsForms10.EDIT.app.0.2780b98_r13_ad1> controltype:= <UIA_EditControlTypeId> ,<50004> , (0000C354)
*** Parent Information ***
Title is: <> Class   := <WindowsForms10.Window.8.app.0.2780b98_r13_ad1> controltype:= <UIA_TableControlTypeId> ,<50036> , (0000C374)

 

The spy demo can identify the all the control types which could not possible by Windows info tool.

But,it could not help to identify the unique name of the selected control as well as selected text of the control.

but, many thanks for your "spy demo" reference its highly useful.

How to run the code in post 71? what do you mean by post 71?

["To print all controls (including non-visible) in Scite console run the code in post 71."]

Thanks

--SJ


 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

You should verify with UISpy.exe or Inspect.exe that you can get the information you need.

In the gray bar just above this text you see the post or reply number (#17) to the right (my name is at the left side). In the UI Automation example by junkew then find post/reply #71. Probably at page 4.

Edited by LarsJ
1 person likes this

Share this post


Link to post
Share on other sites

You should verify with UISpy.exe or Inspect.exe that you can get the information you need.

In the gray bar just above this text you see the post or reply number (#17) to the right (my name is at the left side). In the UI Automation example by junkew then find post/reply #71. Probably at page 4.

 

Hi LarsJ

Thanks for your clarification and i got the response by using script mentioned on post #17 ,

;Response snippet of my grid-view control

Title     = Column1

Class     = 
Ctrl type = 50025
Ctrl name = 
Selected  = False
Handle    = 00000000

 

I am excited after seeing this result :thumbsup: . Now i get some more confident to solve this problem.

How can they read the text inside the grid-view column?

Is this possible to implement same thing to my controls(text-box|combo-box|button)? i also attached my grid-view for your reference

--SJ

post-84013-0-40514200-1387533522_thumb.p

Share this post


Link to post
Share on other sites

Infragistics seems to be having full support for ui automation and as such you should be able to get to the grid interfaces to get the details

unfortunately I do not have a demo application available to check / enhance the AU3 ui automation UDF

but see these links

http://help.infragistics.com/Help/Doc/WPF/2012.1/CLR4.0/html/Developers_Guide_UI_Automation_Support.html

http://www.infragistics.com/help/windows-forms/Coded_UI_Test_Extension_Overview.html

http://www.infragistics.com/help/windows-forms/Using_the_Coded_UI_Test_Extension.html

1 person likes this

Share this post


Link to post
Share on other sites

Infragistics seems to be having full support for ui automation and as such you should be able to get to the grid interfaces to get the details

unfortunately I do not have a demo application available to check / enhance the AU3 ui automation UDF

but see these links

http://help.infragistics.com/Help/Doc/WPF/2012.1/CLR4.0/html/Developers_Guide_UI_Automation_Support.html

http://www.infragistics.com/help/windows-forms/Coded_UI_Test_Extension_Overview.html

http://www.infragistics.com/help/windows-forms/Using_the_Coded_UI_Test_Extension.html

Hi,

I would like to do UI automation test by using AutoIt+Cucumber, Its not my requirement to do it by infragistics coded UI test.

Thanks for your help :) 

--SJ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0