Jump to content

Count the number of controls on a page


dinodod
 Share

Recommended Posts

:whistle:

Is there a function or UDF alrady made that can count the total number of controls on page? I have a dynamic menu system but in my Case statement, I need to know the number of controls on the GUI so I can properly loop thru each item. I have a mix of controls so a counter variable is not possible.

Thanks!

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Link to comment
Share on other sites

I'm not sure that I understand all that you are after - so forgive me if this link is not what you are looking for:

http://www.autoitscript.com/forum/index.ph...showtopic=32077

-MSP-

Smokin, as always. Many thanks.

HerewasPlato, thanks for your help too

I guess I'm not seeing this one. I've used your code and I'm not getting the correct number of controls being sent back to me.

I've looked up WinGetClassList (in the autoit help file) and it doesn't quite make sense to me. It's also 2:30 a.m. here as well.

Thoughts?

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <SQLite.au3>
#include <sqlite.dll.au3>
#include <Array.au3>
#Include <File.au3>

$DBList=_FileListToArray(@scriptdir & "\databases")

GuiCreate("SQL DB Manager", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

    $Treeview           = GuiCtrlCreateTreeview(60, 60, 130, 200)
        $TreeItem_Databases = GUICtrlCreateTreeViewitem("Databases", $Treeview)
            Func_ListDB()
        
        $TreeItem_Queries       = GUICtrlCreateTreeViewitem("Queries", $Treeview)
        GUICtrlSetColor(-1, 0x0000C0)

        ; Content Menu
        $DatabaseContent        = GUICtrlCreateContextMenu($TreeItem_Databases)
        $menuItem_NewDB     = GUICtrlCreateMenuitem ("New", $DatabaseContent)
                           GUICtrlCreateMenuitem ("", $DatabaseContent)    ; separator
        $menuItem_OpenDB        = GUICtrlCreateMenuitem ("Open", $DatabaseContent)


    
    
$Scintilla = _ControlGetCount('', '')
$All = _ControlGetCount("SQL DB Manager","")
MsgBox(0, '', 'Scintilla: ' & $Scintilla & @CRLF & 'All: ' & $All)




Func _ControlGetCount($hWndGUI, $sType = '')
    If $sType = '' Then _
        Return UBound(StringSplit(StringTrimRight(WinGetClassList($hWndGUI), 1), @LF)) - 1
    
    For $iCC = 1 To 4095
        If ControlGetHandle($hWndGUI, '', $sType & $iCC) = 0 Then Return $iCC - 1
    Next
        
    Return SetError(1, 0, '')
EndFunc

Func Func_ListDB()
    For $x = 1 to $DBList[0]
        $SubTreeItem_Databases  = GUICtrlCreateTreeViewitem($DBList[$x], $TreeItem_Databases)
    next
EndFunc
Edited by dinodod

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Link to comment
Share on other sites

  • Moderators

I'm curious... what do you expect the return to be? You don't expect it to return the menus and tree view items do you?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Actually, I am. I have a need to generate a loop to see every control in the gui that is visible. But then a loop from 1 to 4095 (max number of controls in a GUI from what i read), doesn't appear to be bad yet.

The reason is because I am tweaking my Dynamic Menu code and rather than guess at the number of controls, I was thinking it could be easier to perform a count. In larger scenarios, a loop from 1 to 4095 coul slow the system down.

However, I think I have a workaround that might just work. It involves creating an array to hold some values. I hope to finish the code tonight and post it in the Example Code section.

If it works well, I plan on making a couple of different types in order to support treeview menus as well as menubars, etc.

Cross your fingers.

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

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...