Jump to content
Sign in to follow this  
gr1fter

add list of usernames on machine to _GUICtrlTreeView_AddChild

Recommended Posts

gr1fter

Below is what I have now as an example and I can show the current user, but i was like the child list to have every username that is on the machine that is in c:\documents & settings\*

any help in the right direction will be great, thank you!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <GuiTreeView.au3>



$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

$GUI = GUICreate("", 430, 300, -1, -1, -1)
GUISetState (@SW_LOCK)
GUISetBkColor(0xFFFFFF)


Local $GUI, $hItem
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

$hTreeView = _GUICtrlTreeView_Create($GUI, 0, 110, 430, 110, $iStyle)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_GUICtrlTreeView_BeginUpdate($hTreeView)

$hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("Network Users"))


_GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat(@UserName))


_GUICtrlTreeView_EndUpdate($hTreeView)

GUISetState(@SW_ENABLE)
GUISetState(@SW_SHOW)



While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
            Exit
        EndSelect
WEnd





Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_KILLFOCUS ; control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                    _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
;~              Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
;~                  Local $tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
;~                  $hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
;~                  $iIDFrom = DllStructGetData($tinfo, "IDFrom")
;~                  $iCode = DllStructGetData($tinfo, "Code")
;~                  _DebugPrint("$NM_SETCURSOR" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
;~                          "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
;~                          "-->Code:" & @TAB & $iCode & @LF & _
;~                          "-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
;~                          "-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
;~                          "-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
;~                          "-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
;~                          "-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
;~                  Return 0 ; to enable the control to set the cursor
;~                  Return 1 ; nonzero to prevent the control from setting the cursor
                Case $NM_SETFOCUS ; control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                    _DebugPrint("$TVN_BEGINDRAG")
                Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                    _DebugPrint("$TVN_BEGINLABELEDIT")
                Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                    _DebugPrint("$TVN_BEGINRDRAG")
                Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                    _DebugPrint("$TVN_DELETEITEM")
                Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                    _DebugPrint("$TVN_ENDLABELEDIT")
                Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                    _DebugPrint("$TVN_GETDISPINFO")
                Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                    _DebugPrint("$TVN_GETINFOTIP")
                Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                    _DebugPrint("$TVN_ITEMEXPANDED")
                Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                    _DebugPrint("$TVN_ITEMEXPANDING")
                Case $TVN_KEYDOWN
                    _DebugPrint("$TVN_KEYDOWN")
                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    _DebugPrint("$TVN_SELCHANGED")
                Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                    _DebugPrint("$TVN_SELCHANGING")
                Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                    _DebugPrint("$TVN_SETDISPINFO")
                Case $TVN_SINGLEEXPAND
                    _DebugPrint("$TVN_SINGLEEXPAND")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

Share this post


Link to post
Share on other sites
gr1fter

I found a post in search and was able to get half way there, I am now able to display the user names, now I am having trouble reading the data.

How do I determine what is checked in the array?

#AutoIt3Wrapper_outfile=D:\gui.exe

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

$Users = _SystemUsers(2)


$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

$GUI = GUICreate("", 430, 300, -1, -1, -1)
GUISetState (@SW_LOCK)
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_ENABLE)
GUISetState(@SW_SHOW)

$Users = _SystemUsers(2)

$bigbutton = GUICtrlCreateButton("BIG BUTTON", 135, 260, 150, 30, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST)

Local $GUI, $hItem
Local $iStyle = BitOR( $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

$hTreeView = _GUICtrlTreeView_Create($GUI, 0, 110, 430, 110, $iStyle)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_GUICtrlTreeView_BeginUpdate($hTreeView)

$hItem2 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("All Users"))

$hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("Network Users"))



For $i = 1 To $Users[0]

$read = _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat($Users[$i]))

Next

_GUICtrlTreeView_EndUpdate($hTreeView)



While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView,$hItem2)
            MsgBox (0,"", "YOU have ALL USERS checked")
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView,$read)
            MsgBox (0,"", "YOU have an Individual User checked")
        EndSelect
WEnd





Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_KILLFOCUS ; control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                    _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
;~              Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
;~                  Local $tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
;~                  $hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
;~                  $iIDFrom = DllStructGetData($tinfo, "IDFrom")
;~                  $iCode = DllStructGetData($tinfo, "Code")
;~                  _DebugPrint("$NM_SETCURSOR" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
;~                          "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
;~                          "-->Code:" & @TAB & $iCode & @LF & _
;~                          "-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
;~                          "-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
;~                          "-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
;~                          "-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
;~                          "-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
;~                  Return 0 ; to enable the control to set the cursor
;~                  Return 1 ; nonzero to prevent the control from setting the cursor
                Case $NM_SETFOCUS ; control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                    _DebugPrint("$TVN_BEGINDRAG")
                Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                    _DebugPrint("$TVN_BEGINLABELEDIT")
                Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                    _DebugPrint("$TVN_BEGINRDRAG")
                Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                    _DebugPrint("$TVN_DELETEITEM")
                Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                    _DebugPrint("$TVN_ENDLABELEDIT")
                Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                    _DebugPrint("$TVN_GETDISPINFO")
                Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                    _DebugPrint("$TVN_GETINFOTIP")
                Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                    _DebugPrint("$TVN_ITEMEXPANDED")
                Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                    _DebugPrint("$TVN_ITEMEXPANDING")
                Case $TVN_KEYDOWN
                    _DebugPrint("$TVN_KEYDOWN")
                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    _DebugPrint("$TVN_SELCHANGED")
                Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                    _DebugPrint("$TVN_SELCHANGING")
                Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                    _DebugPrint("$TVN_SETDISPINFO")
                Case $TVN_SINGLEEXPAND
                    _DebugPrint("$TVN_SINGLEEXPAND")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint



#cs ===============================================================================
    Function:      _SystemUsers($AccountType = 0)
    Description:   Return an array with the local or domain username
    Parameter(s):  $AccountType: Local, domain or both username
        0 = Local and Domain usernames
        1 = Local usernames only
        2 = Domain usernames only
    Returns:       An array with the list of usernames - Succeeded
        @error 1 - Didn't query any username
        @error 2 - Failed to create Win32_SystemUsers object
        @error 3 - Invalid $AccountType

    Author(s):  Danny35d
#ce ===============================================================================




Func _SystemUsers($AccountType = 0)
    Local $aSystemUsers
    Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $strComputer = "localhost"

    If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '')
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $Output = StringSplit($objItem.PartComponent, ',')
            If IsArray($Output) Then
                $Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '')
                If $AccountType = 0 Or ($AccountType = 1 And @ComputerName = $Temp) Then
                    $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|'
                ElseIf $AccountType = 2 And @ComputerName <> $Temp Then
                    $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|'
                EndIf
            EndIf
        Next
        $aSystemUsers = StringTrimRight($aSystemUsers, 1)
        If $aSystemUsers = '' Then Return(SetError(1, 1, $aSystemUsers))
        Return(SetError(0, 0, StringSplit($aSystemUsers, '|')))
    Else
        $aSystemUsers = ''
        Return(SetError(2, 2, $aSystemUsers))
    EndIf
EndFunc   ;==>_SystemUsers

Share this post


Link to post
Share on other sites
iamtheky

This seems to work if you are only selecting a single item.

since the third object in your tree view matches the first object in the array, I just subtract 2 from the output of the $msg and use that number to reflect which item of the array has been selected.

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView,$hItem2)

MsgBox (0,"", "YOU have ALL USERS checked")

Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView,$read)

$x=$msg - 2

MsgBox (0,"", "YOU have checked " & $Users[$x])

EndSelect

WEnd


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
gr1fter

we are getting there, I added that in and now it does display, but only if have everything checked in that section.

for example, i have 2 user names listed under Network users.

If i choose the first user name and hit the button, i get nothing.

If i choose the bottom user name and hit the button, i get nothing.

If i choose both first and bottom user name and hit button, i get the message prompt

Share this post


Link to post
Share on other sites
iamtheky

You need variables and cases for the maximum number of items (in my example that number was 4), still janky but one step closer.

#AutoIt3Wrapper_outfile=D:\gui.exe

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

$Users = _SystemUsers(2)

AutoItSetOption("MustDeclareVars", 0)

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

$GUI = GUICreate("", 430, 300, -1, -1, -1)
GUISetState (@SW_LOCK)
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_ENABLE)
GUISetState(@SW_SHOW)

Global $Users = _SystemUsers(2)

Global $bigbutton = GUICtrlCreateButton("BIG BUTTON", 135, 260, 150, 30, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST)

Local $GUI, $hItem
Local $iStyle = BitOR( $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

Global $hTreeView = _GUICtrlTreeView_Create($GUI, 0, 110, 430, 110, $iStyle)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_GUICtrlTreeView_BeginUpdate($hTreeView)

Global $hItem2 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("All Users"))

Global $read1 , $read2 , $read3 , $read4 , $read5 , $read6

$size =  ubound ($array) - 2
for $i = 0 to 3 step +1 


If $read1 = '' Then
$read1 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$a = $i
elseif $read2 = '' Then
$read2 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$b = $i
elseif $read3 = '' Then
$read3 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$c = $i
elseif $read4 = '' Then
$read4 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$d = $i
endif

next
_GUICtrlTreeView_EndUpdate($hTreeView)

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE  
            Exit
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView,$hItem2)
            MsgBox (0,"", "YOU have ALL USERS checked")
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b] & ' and ' & $array[$c] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b] & ' and ' & $array[$c])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$c] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$b] & ' and ' & $array[$c] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$c])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$b] & ' and ' & $array[$c])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$b] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$c] & ' and ' & $array[$d])
        Case $msg =$bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read1)
            MsgBox (0,"", "YOU have checked " & $array[$a])
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read2)
            MsgBox (0,"", "YOU have checked " & $array[$b])
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$c])
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$d])

EndSelect
    

Wend

exit


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_KILLFOCUS ; control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                    _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
;~              Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
;~                  Local $tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
;~                  $hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
;~                  $iIDFrom = DllStructGetData($tinfo, "IDFrom")
;~                  $iCode = DllStructGetData($tinfo, "Code")
;~                  _DebugPrint("$NM_SETCURSOR" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
;~                          "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
;~                          "-->Code:" & @TAB & $iCode & @LF & _
;~                          "-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
;~                          "-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
;~                          "-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
;~                          "-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
;~                          "-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
;~                  Return 0 ; to enable the control to set the cursor
;~                  Return 1 ; nonzero to prevent the control from setting the cursor
                Case $NM_SETFOCUS ; control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                    _DebugPrint("$TVN_BEGINDRAG")
                Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                    _DebugPrint("$TVN_BEGINLABELEDIT")
                Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                    _DebugPrint("$TVN_BEGINRDRAG")
                Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                    _DebugPrint("$TVN_DELETEITEM")
                Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                    _DebugPrint("$TVN_ENDLABELEDIT")
                Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                    _DebugPrint("$TVN_GETDISPINFO")
                Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                    _DebugPrint("$TVN_GETINFOTIP")
                Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                    _DebugPrint("$TVN_ITEMEXPANDED")
                Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                    _DebugPrint("$TVN_ITEMEXPANDING")
                Case $TVN_KEYDOWN
                    _DebugPrint("$TVN_KEYDOWN")
                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    _DebugPrint("$TVN_SELCHANGED")
                Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                    _DebugPrint("$TVN_SELCHANGING")
                Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                    _DebugPrint("$TVN_SETDISPINFO")
                Case $TVN_SINGLEEXPAND
                    _DebugPrint("$TVN_SINGLEEXPAND")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint



#cs ===============================================================================
    Function:      _SystemUsers($AccountType = 0)
    Description:   Return an array with the local or domain username
    Parameter(s):  $AccountType: Local, domain or both username
        0 = Local and Domain usernames
        1 = Local usernames only
        2 = Domain usernames only
    Returns:       An array with the list of usernames - Succeeded
        @error 1 - Didn't query any username
        @error 2 - Failed to create Win32_SystemUsers object
        @error 3 - Invalid $AccountType

    Author(s):  Danny35d
    ****MODIFIED************
#ce ===============================================================================




Func _SystemUsers($AccountType = 0)
    Local $aSystemUsers
    Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $strComputer = "localhost"
    
    If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '')
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

        For $objItem In $colItems
            $Output = StringSplit($objItem.PartComponent, ',')
            
                $Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '')
                
                    $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & ","

next

Global $Array = stringsplit ($aSystemUsers , "," , 2)

EndFunc   ;==>_SystemUsers

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
gr1fter

You need variables and cases for the maximum number of items (in my example that number was 4), still janky but one step closer.

#AutoIt3Wrapper_outfile=D:\gui.exe

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

$Users = _SystemUsers(2)

AutoItSetOption("MustDeclareVars", 0)

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

$GUI = GUICreate("", 430, 300, -1, -1, -1)
GUISetState (@SW_LOCK)
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_ENABLE)
GUISetState(@SW_SHOW)

Global $Users = _SystemUsers(2)

Global $bigbutton = GUICtrlCreateButton("BIG BUTTON", 135, 260, 150, 30, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST)

Local $GUI, $hItem
Local $iStyle = BitOR( $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

Global $hTreeView = _GUICtrlTreeView_Create($GUI, 0, 110, 430, 110, $iStyle)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_GUICtrlTreeView_BeginUpdate($hTreeView)

Global $hItem2 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("All Users"))

Global $read1 , $read2 , $read3 , $read4 , $read5 , $read6

$size =  ubound ($array) - 2
for $i = 0 to 3 step +1 


If $read1 = '' Then
$read1 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$a = $i
elseif $read2 = '' Then
$read2 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$b = $i
elseif $read3 = '' Then
$read3 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$c = $i
elseif $read4 = '' Then
$read4 = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i]))
$d = $i
endif

next
_GUICtrlTreeView_EndUpdate($hTreeView)

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE  
            Exit
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView,$hItem2)
            MsgBox (0,"", "YOU have ALL USERS checked")
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b] & ' and ' & $array[$c] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b] & ' and ' & $array[$c])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$c] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$b] & ' and ' & $array[$c] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read2) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$b])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$c])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read1) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$a] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$b] & ' and ' & $array[$c])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read2) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$b] & ' and ' & $array[$d])
        Case $msg= $bigbutton And  _GUICtrlTreeView_GetChecked($hTreeView, $read3) AND _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$c] & ' and ' & $array[$d])
        Case $msg =$bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read1)
            MsgBox (0,"", "YOU have checked " & $array[$a])
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read2)
            MsgBox (0,"", "YOU have checked " & $array[$b])
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read3) 
            MsgBox (0,"", "YOU have checked " & $array[$c])
        Case $msg= $bigbutton And _GUICtrlTreeView_GetChecked($hTreeView, $read4) 
            MsgBox (0,"", "YOU have checked " & $array[$d])

EndSelect
    

Wend

exit


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_KILLFOCUS ; control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                    _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
;~              Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
;~                  Local $tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
;~                  $hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
;~                  $iIDFrom = DllStructGetData($tinfo, "IDFrom")
;~                  $iCode = DllStructGetData($tinfo, "Code")
;~                  _DebugPrint("$NM_SETCURSOR" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
;~                          "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
;~                          "-->Code:" & @TAB & $iCode & @LF & _
;~                          "-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
;~                          "-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
;~                          "-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
;~                          "-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
;~                          "-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
;~                  Return 0 ; to enable the control to set the cursor
;~                  Return 1 ; nonzero to prevent the control from setting the cursor
                Case $NM_SETFOCUS ; control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                    _DebugPrint("$TVN_BEGINDRAG")
                Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                    _DebugPrint("$TVN_BEGINLABELEDIT")
                Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                    _DebugPrint("$TVN_BEGINRDRAG")
                Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                    _DebugPrint("$TVN_DELETEITEM")
                Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                    _DebugPrint("$TVN_ENDLABELEDIT")
                Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                    _DebugPrint("$TVN_GETDISPINFO")
                Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                    _DebugPrint("$TVN_GETINFOTIP")
                Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                    _DebugPrint("$TVN_ITEMEXPANDED")
                Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                    _DebugPrint("$TVN_ITEMEXPANDING")
                Case $TVN_KEYDOWN
                    _DebugPrint("$TVN_KEYDOWN")
                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    _DebugPrint("$TVN_SELCHANGED")
                Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                    _DebugPrint("$TVN_SELCHANGING")
                Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                    _DebugPrint("$TVN_SETDISPINFO")
                Case $TVN_SINGLEEXPAND
                    _DebugPrint("$TVN_SINGLEEXPAND")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint



#cs ===============================================================================
    Function:      _SystemUsers($AccountType = 0)
    Description:   Return an array with the local or domain username
    Parameter(s):  $AccountType: Local, domain or both username
        0 = Local and Domain usernames
        1 = Local usernames only
        2 = Domain usernames only
    Returns:       An array with the list of usernames - Succeeded
        @error 1 - Didn't query any username
        @error 2 - Failed to create Win32_SystemUsers object
        @error 3 - Invalid $AccountType

    Author(s):  Danny35d
    ****MODIFIED************
#ce ===============================================================================




Func _SystemUsers($AccountType = 0)
    Local $aSystemUsers
    Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $strComputer = "localhost"
    
    If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '')
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

        For $objItem In $colItems
            $Output = StringSplit($objItem.PartComponent, ',')
            
                $Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '')
                
                    $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & ","

next

Global $Array = stringsplit ($aSystemUsers , "," , 2)

EndFunc   ;==>_SystemUsers

This is def a step closer! However the 4 static entries is still a problem as there are sometimes more than 4 entries and sometimes less than 4 entries.

I was thinking what if we set a high number of entries, like 10 or 15 and if the entry is blank it will not produce a _GUICtrlTreeView_Add($hTreeView, 0, StringFormat($Array[$i])) and if there is an entry it will...

that could possibly work you think?

or if i could determine the amount that this array produces

Global $Array = stringsplit ($aSystemUsers , "," , 2)

I could plug that number into this line to give me the right amount of treeview lines

for $i = 0 to (number from array) step +1
Edited by gr1fter

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.