Jump to content
Sign in to follow this  
Nezoic

General GUI Questions

Recommended Posts

Nezoic

Is there anything like _isSelected for Tree Views?

Also for is there a way to identify tree variables writen as such...

I ask this because in code like the following that builds a tree from a .ini file it would be most helpfull.

$treeview = GUICtrlCreateTreeView(6, 20, 150, 250, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)

$sections = IniReadSectionNames("testmacrolist.ini")
For $i = 1 To $sections[0]
   $keys = IniReadSection("testmacrolist.ini", $sections[$i])
   $item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
   For $x = 1 To $keys[0][0]
      GUICtrlCreateTreeViewItem($keys[$x][0], $item)
   Next
Next

testmacrolist.ini

[Macro1]

Event1 =

Event2 =

[Macro2]

Event1 =

Event2 =

So in other words if you tried to check

Case $msg = $sections[1]

it wouldn't know what to do since $sections[1] is now a string (Macro1) instead of a pointer to the variable?

$sections[1] needs to be

$Macro1 and $Macro1 = GUICtrlCreateTreeViewItem("Macro1", $treeview)

Here is my total code and the makeshift way I got around part of my problems by basically writing every section and key from the .ini into a tree variable that is #included into the code.

Something like _ListTree that would show every variable and its value and or _isSelected that you could question those variables would be excellent for viewing what my array spit out into a tree.

Global $xPos, $yPos
dim $sectData, $KeyData, $ValData, $tempData 
#include <GUIConstants.au3>
#Include <Constants.au3>
#include <array.au3>
If WinExists("Macro v1.0") Then winclose("Macro v1.0")
;===================================> GUI <=======================================
GUICreate("Macro v1.0", 400, 430)
$filemenu = GUICtrlCreateMenu ("File")
$optionsmenu = GUICtrlCreateMenu ("Options")
$helpmenu = GUICtrlCreateMenu ("?")
$Fileitem = GUICtrlCreateMenuitem ("New",$filemenu)
$Fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
$Fileitem = GUICtrlCreateMenuitem ("Save",$filemenu)
$Fileitem = GUICtrlCreateMenuitem ("Exit",$filemenu)
$optionsitem = GUICtrlCreateMenuitem ("Even Window", $optionsmenu)

$eventsgroup = GUICtrlCreateGroup ("Events",170,5,135,275)

GUICtrlCreateLabel ( "Color", 218, 170, 40, 20)
$Color = GUICtrlCreateInput ( 0, 210, 185, 50, 20)

GUICtrlCreateLabel ( "Locked", 215, 205, 40, 20)
$xPosLocked = GUICtrlCreateInput ( 0, 195, 220, 40, 20)
$yPosLocked = GUICtrlCreateInput ( 0, 240, 220, 40, 20)

GUICtrlCreateLabel ( "Current", 215, 240, 40, 20)
$xPos = GUICtrlCreateInput ( 0, 195, 255, 40, 20)
$yPos = GUICtrlCreateInput ( 0, 240, 255, 40, 20)

$btnNew = GUICtrlCreateButton("New", 335, 15, 60)
$btnSave = GUICtrlCreateButton("Save", 335, 45, 60)
$btnLoad = GUICtrlCreateButton("Load", 335, 75, 60)
$btnPlay = GUICtrlCreateButton("Play", 335, 115, 50)
$btnStop = GUICtrlCreateButton("Stop", 335, 145, 50)
$btnPause = GUICtrlCreateButton("Pause", 335, 175, 50)

$treeview = GUICtrlCreateTreeView(6, 20, 150, 250, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)
$sections = IniReadSectionNames("testmacrolist.ini")    
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $SectData = _ArrayCreate("")
    $KeyData = _ArrayCreate("")
    $ValData = _ArrayCreate("")
        $tempData = _ArrayCreate("")
    For $i = 1 To $sections[0]
            _ArrayAdd($SectData, $sections[$i])
            $keys = IniReadSection("testmacrolist.ini", $sections[$i])
           ;$item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
            _ArrayAdd($tempData, "$" & $sectData[$i] & " = GUICtrlCreateTreeViewItem(" & '"' & $sectData[$i] & '"' & ", " & "$treeview)")   
            For $x = 1 To $keys[0][0]
                _ArrayAdd($KeyData, $Keys[$x][0])
                _ArrayAdd($ValData, $Keys[$x][1])
                _ArrayAdd($tempData, "$" & $keys[$x][0] & " = GUICtrlCreateTreeViewItem(" & '"' & $keys[$x][0] & '"' & ", " & "$" &  $sectData[$i] & ")")   
               ;GUICtrlCreateTreeViewItem($keys[$x][0], $item)
            Next
        
        Next
    EndIf
    
    $file1 = FileOpen("vardata.au3", 2)
    $file2 = FileOpen("sectdata.au3", 2)
    if $file1 = -1 OR $file2 = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    For $f = 0 to UBound($tempData, 1) - 1
        FileWrite($file1, $tempData[$f] & @CRLF)
    next
;   FileWriteLine($file2, "Select")
    For $f2 = 1 to $sections[0]
        FileWriteLine($file2, "Case $msg = " & "$" & $sections[$f2])
        FileWriteLine($file2, "GUIctrlSetState ($eventsgroup,$GUI_SHOW)")
    FileWriteLine($file2, "GUIctrlSetState ($xPos,$GUI_SHOW)")
    FileWriteLine($file2, "GUIctrlSetState ($yPos,$GUI_SHOW)")
    FileWriteLine($file2, "GUIctrlSetState ($xPosLocked,$GUI_HIDE)")
        FileWriteLine($file2, "GUIctrlSetState ($yPosLocked,$GUI_HIDE)")
    Next
;   FileWriteLine($file2, "EndSelect")
    FileClose($file1)
    FileClose($file2)

MsgBox(0, "test", $sections[1])
GUISetState()
;================================> End GUI <======================================
#include<Vardata.au3>
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop   
  
    $pos = MouseGetPos()
    GUICtrlSetData($xPos, $pos[0])
    GUICtrlSetData($yPos, $pos[1])
    If _IsPressed('02') = 1 Then PosLock()
    GUISetState()
;   #include<sectData.au3>

    Select

        Case $msg = -3 Or $msg = -1
            ExitLoop
    Case $msg = $Macro1
        GUIctrlSetState ($eventsgroup,$GUI_SHOW)
        GUIctrlSetState ($xPos,$GUI_SHOW)
        GUIctrlSetState ($yPos,$GUI_SHOW)
        GUIctrlSetState ($xPosLocked,$GUI_HIDE)
        GUIctrlSetState ($yPosLocked,$GUI_HIDE)
         
    
    EndSelect
   
sleep(10)   
WEnd

GUIDelete()
Exit

Func PosLock()
   GUICtrlSetData($xPosLocked, $pos[0])
   GUICtrlSetData($yPosLocked, $pos[1])
   $colur = PixelGetColor( $pos[0] , $pos[1])
   $colur = Hex($colur, 6)
   GUICtrlSetData ($Color, $colur)
   $bkcolur = '0x' & $colur
   GUICtrlSetBkColor ($treeview, $bkcolur)
EndFunc

Func _IsPressed($hexKey)
  Local $aR, $bO
  
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
  
  Return $bO
EndFunc

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  

×