Jump to content

How to get all controls in a window


riki381
 Share

Recommended Posts

Hi,

Im a newbie and i would appreciate any help.

My question is:

How can you get all controls in a window, if all you have is the window handle?

I have this exe window, but i dont know which controls were used in this application.

Thanks,

riki381

Link to comment
Share on other sites

#include "Array.au3"
Opt("WinTitleMatchMode", 4)
$aArray = _WinGetControls('[class:Shell_TrayWnd]')
_ArrayDisplay($aArray)


Func _WinGetControls($Title, $Text="")
Local $WndControls, $aControls, $sLast="", $n=1
$WndControls = WinGetClassList($Title, $Text)
$aControls = StringSplit($WndControls, @CRLF)
Dim $aResult[$aControls[0]+1][2]
For $i = 1 To $aControls[0]
    If $aControls[$i] <> "" Then
        If $sLast = $aControls[$i] Then 
            $n+=1
        Else
            $n=1
        EndIf
        $aControls[$i] &= $n
        $sLast = StringTrimRight($aControls[$i],1)
    EndIf
    If $i < $aControls[0] Then 
        $aResult[$i][0] = $aControls[$i]
    Else ; last item in array
        $aResult[$i][0] = WinGetTitle($Title) ; return WinTitle
    EndIf
    $aResult[$i][1] = ControlGetHandle($Title, $Text, $aControls[$i])   
Next
$aResult[0][0] = "ClassnameNN"
$aResult[0][1] = "Handle"
Return $aResult
EndFunc

this should do the trick :)

Edited by iLoveAU3
Link to comment
Share on other sites

  • 4 years later...
  • 5 years later...

I tried to use this function, it works fine on a window that has controls that have same classname. When I tried to use for a window that has runtime ListBox with list values as popup, the WinGetClassList returns empty array!!

May I know if there are any other alternatives to hit the hidden ListBox and get those values? Please help.


 
Link to comment
Share on other sites

Only the old Win32 stuff that can be interacted using standard AutoIt will show up most likely. If you are on Windows 10 then there is PLENTY that won't find or return data because it cannot interact with them.

Post your code for more help and tell us what windows you are having issues with.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

#include "MsgBoxConstants.au3"
#include ".\libs\UIAWrappers.au3"
#include ".\libs\CUIAutomation2.au3"
#include "MsgBoxConstants.au3"
#include ".\libs\CUIAutomation2.au3"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <FileConstants.au3>
#include ".\libs\ISimpleDOM.au3"
#include ".\libs\MSAccessibility.au3"
#include "WinAPIProc.au3"
#include "WinAPISys.au3"
#include "APISysConstants.au3"
#include "GUIConstantsEx.au3"
#include <GUIListView.au3>

; AutoItSetOption("MustDeclareVars", 1)
Sleep(10000)

_UIA_setVar("Global.Highlight", True)

; Wait 50 seconds for the Notepad window to appear.
WinWait("[Title:Edit Template - Basic FORM Template]", "", 50)

; Retrieve the handle of the Edit Template window...
WinActivate("[Title:Edit Template - Basic FORM Template]", "")
Local $hWnd = WinGetHandle("[Title:Edit Template - Basic FORM Template]")
;MsgBox($MB_SYSTEMMODAL, "INFO", $hWnd)
$iCmd = 6
Local $hWnd1 = _WinAPI_GetWindow ( $hWnd, $iCmd )
Sleep(500)    ;
;_WinAPI_CloseWindow($hWnd1)    ;

$sClassList = WinGetClassList($hWnd1)
_ArrayDisplay($sClassList)

;~ $hWndCtrl=ControlGetHandle($hWnd1,"","[class:ListBox index:4]")
;~ MsgBox($MB_SYSTEMMODAL, "INFO", $hWndCtrl)

MsgBox($MB_SYSTEMMODAL, "INFO", "DONE")

Edited by RadicalKoncepts
Link to comment
Share on other sites

The ListBox is a run populated - meaning When we click on a button, it displays as Listbox with items populated. I am not able to get handle of that listbox which gets displayed at runtime.

Note - I used Inspect.exe and found its associated classname as well. Not sure where I am going wrong here.

Link to comment
Share on other sites

what operating system is this running on? also, when posting code, use the Code Tags <> in the bar above where you type and put code in that, it stays nice and formatted, like this

#include "MsgBoxConstants.au3"
#include ".\libs\UIAWrappers.au3"
#include ".\libs\CUIAutomation2.au3"
#include "MsgBoxConstants.au3"
#include ".\libs\CUIAutomation2.au3"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <FileConstants.au3>
#include ".\libs\ISimpleDOM.au3"
#include ".\libs\MSAccessibility.au3"
#include "WinAPIProc.au3"
#include "WinAPISys.au3"
#include "APISysConstants.au3"
#include "GUIConstantsEx.au3"
#include <GUIListView.au3>

; AutoItSetOption("MustDeclareVars", 1)
Sleep(10000)

_UIA_setVar("Global.Highlight", True)

; Wait 50 seconds for the Notepad window to appear.
WinWait("[Title:Edit Template - Basic MBO Template]", "", 50)

; Retrieve the handle of the Edit Template window...
WinActivate("[Title:Edit Template - Basic MBO Template]", "")
Local $hWnd = WinGetHandle("[Title:Edit Template - Basic MBO Template]")
;MsgBox($MB_SYSTEMMODAL, "IntergyVisitNote", $hWnd)
$iCmd = 6
Local $hWnd1 = _WinAPI_GetWindow ( $hWnd, $iCmd )
Sleep(500)    ;
;_WinAPI_CloseWindow($hWnd1)    ;

$sClassList = WinGetClassList($hWnd1)
_ArrayDisplay($sClassList)

;~ $hWndCtrl=ControlGetHandle($hWnd1,"","[class:ListBox index:4]")
;~ MsgBox($MB_SYSTEMMODAL, "IntergyVisitNote", $hWndCtrl)

MsgBox($MB_SYSTEMMODAL, "IntergyVisitNote", "DONE")

 

If you running on Windows 10, you need to be using UIAutomation stuff.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

you will have to wait for others to assist with that. i have never done it myself and don't have time to mess with it today. Just to be clear, is it notepad that is giving you issues?

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...