Sign in to follow this  
Followers 0
PhoenixXL

[Solved] Control Count

4 posts in this topic

#1 ·  Posted (edited)

Hello Every,

I needed to find out the total number of controls in a GUI

This is what i have done so far..

#include-once
#include <WinAPI.au3>

$hGui= GUICreate('InputBoxEx || Phoenix XL', Default, Default, -1, -1 , 0x80000000, BITOR(0x00000080,0x00000008))
GUICtrlCreateButton('Hello',10,10,100,100)
GUICtrlCreateButton('Hello',10,110,100,100)
GUISetState()
GUISetBkColor(0)

Func _GetControlCount($nGUi=0)
Local $nPrevious=-1
If $nGui<>0 Then $nPrevious=GUISwitch($nGui)
Local $Ctl=3
Local $hWnd
While 1
$hWnd=GUICtrlGetHandle($Ctl)
If $hWnd=0 Then ExitLoop
ConsoleWrite('Handle_'&$Ctl&':'&$hWnd&@TAB&'ClassName:'&_WinAPI_GetClassName($hWnd)&@CR)
$Ctl+=1
WEnd
If $nPrevious<>-1 Then GUISwitch($nPrevious)
Return $Ctl-3
EndFunc

ConsoleWrite(_GetControlCount()&@CR)

While 1
Sleep(10)
WEnd

;Not Required
Func GetNextDlgGroupItem($hWnd,$Start_Ctl=0,$_Previous=False)
Local $aRet=DllCall('User32.dll','hwnd','GetNextDlgGroupItem','hwnd',$hWnd,'hwnd',$Start_Ctl,'bool',$_Previous)
If @error Then Return SetError(1,@error,-1)
Return $aRet[0]
EndFunc

It works pretty well but i have some doubts

Why is it that the fisrt control created has the ID '3' and not '0'|'1'

One more doubt

Till now i havent encountered any problems simultaneously im not having the concept how it works

therefore please tell me will it work for any window created using Autoit

Thanks for you time

Regards

PXL :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include-once
Opt('TrayIconDebug',1)
$hGui= GUICreate('InputBoxEx || Phoenix XL')
GUICtrlCreateButton('Hello',10,10,100,100)
GUICtrlCreateButton('Hello',10,110,100,100)
GUISetBkColor(0)
GUISetState()


Func _ControlListToArray($nHwnd,$Reverse=False)
    If Not IsHWnd($nHwnd) Then Return SetError(1,0,-1)
    Local $nIndex[2]=[0]
    Local $lstHwnd=0
    While 1
        $nIndex[$nIndex[0]+1]=GetNextTabGroupItem($nHwnd,$lstHwnd,$Reverse)
        Switch IsHWnd($nIndex[$nIndex[0]+1])
            Case 0
                Return SetError(2,0,-1)
            Case 1
                For $n=1 To $nIndex[0]-1
                    If $nIndex[$n]=$nIndex[$nIndex[0]+1] Then
                        ReDim $nIndex[$nIndex[0]+1]
                        Return SetError(0,$nIndex[0],$nIndex)
                    EndIf
                Next
        EndSwitch
        $lstHwnd=$nIndex[$nIndex[0]+1]
        $nIndex[0]+=1
        ReDim $nIndex[$nIndex[0]+2]
    WEnd
    Return SetError(0,$nIndex+1,$nIndex)
EndFunc

Local $x = _ControlListToArray($hGui)
MsgBox(0,'',@extended&' Controls With TabStop Style')
For $i=1 To $x[0]
    ConsoleWrite('Hanle_'&$i&'  '&$x[$i]&@CR)
Next

While GUIGetMsg()<>-3
    Sleep(10)
WEnd

Func GetNextTabGroupItem($hWnd,$Start_Ctl=0,$_Previous=False)
    Local $aRet=DllCall('User32.dll','hwnd','GetNextDlgTabItem','hwnd',$hWnd,'hwnd',$Start_Ctl,'bool',$_Previous)
    If @error Then Return SetError(1,@error,-1)
    Return $aRet[0]
EndFunc

The above works as well but if the $WS_TABSTOP style is removed it doesnt work and with the first example non Autoit - GUI are not detected

Reason : I wanted to write a function for an GUI based UDF which would require to get the total number of edits present in the current Window

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Is that help you in any way?

#include <Array.au3>

$hMain = GUICreate("Example")
For $i = 1 To Random(10,15,1)
    Switch Random(1,3,1)
        Case 1
            GUICtrlCreateButton("Some button",Random(0,300,1),Random(0,380,1),70,20)
        Case 2
            GUICtrlCreateLabel("Some label",Random(0,300,1),Random(0,380,1),70,20)
        Case 3
            GUICtrlCreateInput("Some input",Random(0,300,1),Random(0,380,1),70,20)
    EndSwitch
Next
GUISetState(@SW_SHOW,$hMain)

$ClassList = StringSplit(StringTrimRight(WinGetClassList($hMain),1),@LF)
_ArrayDisplay($ClassList)

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Thanks Andreik,

didn't knew the Func 'WinGetClassList()'

It solved the problem :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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