Jump to content

need help with GUIgetmsg()


bobbintb
 Share

Recommended Posts

ok so here is my problem. i have a script that when i select a list of folders they are saved in a 2d array. additional options are also stored in the array by changes made to the gui (radio buttons, input fields etc.) now i cant get the gui to reflect the changes made to the variable when i select a different item in the list. here is my code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=c:\users\zero\documents\img.kxf
$num = 1
Global $array[$num][5]
$Form1_1 = GUICreate("Form1", 658, 536, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Delete after success", 520, 16, 121, 17)
$add = GUICtrlCreateButton("Add", 520, 40, 75, 25, $WS_GROUP)
$remove = GUICtrlCreateButton("Remove", 520, 72, 75, 25, $WS_GROUP)
$clear = GUICtrlCreateButton("Clear All", 520, 104, 75, 25, $WS_GROUP)
$run = GUICtrlCreateButton("Run", 528, 392, 75, 25, $WS_GROUP)
$load = GUICtrlCreateButton("Load", 528, 454, 75, 25, $WS_GROUP)
$save = GUICtrlCreateButton("Save", 528, 486, 75, 25, $WS_GROUP)
$List1 = GUICtrlCreateList($array, 8, 8, 505, 409)
$Radio1 = GUICtrlCreateRadio("DVD", 528, 144, 113, 17)
$Radio2 = GUICtrlCreateRadio("Blu Ray", 528, 184, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("Label:", 8, 420)
$Label = GUICtrlCreateInput("", 8, 440, 409)
GUICtrlCreateLabel("Destination:", 8, 470)
$dest = GUICtrlCreateInput("", 8, 490, 409)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Func _addarray()
    ReDim $array[$num][5]
    $arraytemp = FileSelectFolder("Select ROOT folder.", "", 4)
    $array[$num - 1][0] = $arraytemp
    $num = $num + 1
    GUICtrlSetData($List1, $arraytemp)
    If $arraytemp = "" Then
        $num = $num - 1
    EndIf
EndFunc   ;==>_addarray

Func _clear()
    GUICtrlSetData($List1, "")
    If $num = 1 Then
    Else
        $num = 1
        ReDim $array[$num][5]
        $array[0][0] = ""
    EndIf
EndFunc   ;==>_clear

func radioset()
if $array[_GUICtrlListBox_GetCurSel($List1)][1]="DVD" Then
    MsgBox(0,"","DVD")
Else
        MsgBox(0,"","BLU")
endif
endfunc

While 1
    $nMsg = GUIGetMsg()
    _GUICtrlListView_SetItemSelected($List1, 0)
    GUICtrlSetOnEvent(-1 , "radioset")
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            _addarray()
        Case $remove
            _ArrayDisplay($array)
;~      MsgBox(0,"",GUICtrlRead($Radio2))
        Case $clear
            _clear()
        case $Radio1
;~          MsgBox(0,"",_GUICtrlListBox_GetCurSel($List1))
            $array[_GUICtrlListBox_GetCurSel($List1)][1]="DVD"
            MsgBox(0,"",$nMsg)
        case $Radio2
;~                      MsgBox(0,"",_GUICtrlListBox_GetCurSel($List1))

            $array[_GUICtrlListBox_GetCurSel($List1)][1]="BLU"
                        MsgBox(0,"",$nMsg)

    EndSwitch
WEnd

once ive got a list of folders, i can select one and change options (so far only the radio buttons) and those are stored in the array. now when i select something else, i want the radio button to switch to its proper location based on what the array says. ive been fiddling with GUIgetmsg() to accomplish this but im not even sure thats the right approach and dont really now where to begin looking. can anyone offer me some pointers?

Link to comment
Share on other sites

  • Moderators

bobbintb,

What do you want in the 5 elements of the array? Obviously [0] is the folder name and [1] is "DVD" or "Blu". But are the others are the checkbox and the contents of the 2 inputs?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

bobbintb,

What do you want in the 5 elements of the array? Obviously [0] is the folder name and [1] is "DVD" or "Blu". But are the others are the checkbox and the contents of the 2 inputs?

M23

yes, some will be checkboxes, others will be strings that go in the input fields. i was going to work on those other things once i cleared this hurdle.
Link to comment
Share on other sites

  • Moderators

bobbintb,

This should get you started.

:mellow:

Add, Remove and Clear All work nicely. Save will place the current state of the checkbox, radios and inputs into the array, Load will reset these controls to the saved values:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>

$num = 0
Global $array[1][5]

$Form1_1 = GUICreate("Form1", 658, 536, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Delete after success", 520, 16, 121, 17)
$add = GUICtrlCreateButton("Add", 520, 40, 75, 25)
$remove = GUICtrlCreateButton("Remove", 520, 72, 75, 25)
$clear = GUICtrlCreateButton("Clear All", 520, 104, 75, 25)
$run = GUICtrlCreateButton("Run", 528, 392, 75, 25)
$load = GUICtrlCreateButton("Load", 528, 454, 75, 25)
$save = GUICtrlCreateButton("Save", 528, 486, 75, 25)
$List1 = GUICtrlCreateList($array, 8, 8, 505, 409)
$Radio1 = GUICtrlCreateRadio("DVD", 528, 144, 113, 17)
$Radio2 = GUICtrlCreateRadio("Blu Ray", 528, 184, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("Label:", 8, 420)
$Label = GUICtrlCreateInput("", 8, 440, 409)
GUICtrlCreateLabel("Destination:", 8, 470)
$dest = GUICtrlCreateInput("", 8, 490, 409)
GUISetState(@SW_SHOW)

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            _addarray()
        Case $remove
            ; Read selection
            $sSelectedFolder = GUICtrlRead($List1)
            ; Find position in array
            $iIndex = _ArraySearch($array, $sSelectedFolder)
            ; Delete that index
            _ArrayDelete($array, $iIndex)
            $num -= 1
            ; Clear list and reload
            $sListData = "|"
            For $i = 0 To $num - 1
                $sListData &= $array[$i][0] & "|"
            Next
            GUICtrlSetData($List1, $sListData)
;~      MsgBox(0,"",GUICtrlRead($Radio2))
        Case $clear
            _clear()
        Case $save
            ; Read selection
            $sSelectedFolder = GUICtrlRead($List1)
            ; Find position in array
            $iIndex = _ArraySearch($array, $sSelectedFolder)
            ; Save elements into array
            If GUICtrlRead($Radio1) = 1 Then
                $array[$iIndex][1] = "DVD"
            Else
                $array[$iIndex][1] = "Blu"
            EndIf
            If GUICtrlRead($Checkbox1) = 1 Then
                $array[$iIndex][2] = "Delete"
            Else
                $array[$iIndex][2] = ""
            EndIf
            $array[$iIndex][3] = GUICtrlRead($Label)
            $array[$iIndex][4] = GUICtrlRead($dest)
        Case $load
            ; Read selection
            $sSelectedFolder = GUICtrlRead($List1)
            ; Find position in array
            $iIndex = _ArraySearch($array, $sSelectedFolder)
            ; Now set the various controls to the state saved in the array
            If $array[$iIndex][1] = "DVD" Then
                GUICtrlSetState($Radio1, $GUI_CHECKED)
                GUICtrlSetState($Radio2, $GUI_UNCHECKED)
            Else
                GUICtrlSetState($Radio1, $GUI_UNCHECKED)
                GUICtrlSetState($Radio2, $GUI_CHECKED)
            EndIf
            If $array[$iIndex][2] = "Delete" Then
                GUICtrlSetState($Checkbox1, $GUI_CHECKED)
            Else
                GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
            EndIf
            GUICtrlSetData($Label, $array[$iIndex][3])
            GUICtrlSetData($dest, $array[$iIndex][4])

    EndSwitch

WEnd

Func _addarray()

    ; Increase count and redim array
    $num = $num + 1
    ReDim $array[$num][5]
    ; Get new folder and add to array
    $sFolder = FileSelectFolder("Select ROOT folder.", "", 4)
    $array[$num - 1][0] = $sFolder
    $array[$num - 1][1] = "DVD"
    ; Clear list and reload
    $sListData = "|"
    For $i = 0 To $num - 1
        $sListData &= $array[$i][0] & "|"
    Next
    GUICtrlSetData($List1, $sListData)

EndFunc   ;==>_addarray

Func _clear()

    GUICtrlSetData($List1, "|")
    Global $array[1][5]
    $num = 0

EndFunc   ;==>_clear

Good luck with the rest of the project! :(

M23

Edit: Typnig!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

bobbintb,

This should get you started.

:mellow:

Add, Remove and Clear All work nicely. Save will place the current state of the checkbox, radios and inputs into the array, Load will reset these controls to the saved values:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>

$num = 0
Global $array[1][5]

$Form1_1 = GUICreate("Form1", 658, 536, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Delete after success", 520, 16, 121, 17)
$add = GUICtrlCreateButton("Add", 520, 40, 75, 25)
$remove = GUICtrlCreateButton("Remove", 520, 72, 75, 25)
$clear = GUICtrlCreateButton("Clear All", 520, 104, 75, 25)
$run = GUICtrlCreateButton("Run", 528, 392, 75, 25)
$load = GUICtrlCreateButton("Load", 528, 454, 75, 25)
$save = GUICtrlCreateButton("Save", 528, 486, 75, 25)
$List1 = GUICtrlCreateList($array, 8, 8, 505, 409)
$Radio1 = GUICtrlCreateRadio("DVD", 528, 144, 113, 17)
$Radio2 = GUICtrlCreateRadio("Blu Ray", 528, 184, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("Label:", 8, 420)
$Label = GUICtrlCreateInput("", 8, 440, 409)
GUICtrlCreateLabel("Destination:", 8, 470)
$dest = GUICtrlCreateInput("", 8, 490, 409)
GUISetState(@SW_SHOW)

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            _addarray()
        Case $remove
            ; Read selection
            $sSelectedFolder = GUICtrlRead($List1)
            ; Find position in array
            $iIndex = _ArraySearch($array, $sSelectedFolder)
            ; Delete that index
            _ArrayDelete($array, $iIndex)
            $num -= 1
            ; Clear list and reload
            $sListData = "|"
            For $i = 0 To $num - 1
                $sListData &= $array[$i][0] & "|"
            Next
            GUICtrlSetData($List1, $sListData)
;~      MsgBox(0,"",GUICtrlRead($Radio2))
        Case $clear
            _clear()
        Case $save
            ; Read selection
            $sSelectedFolder = GUICtrlRead($List1)
            ; Find position in array
            $iIndex = _ArraySearch($array, $sSelectedFolder)
            ; Save elements into array
            If GUICtrlRead($Radio1) = 1 Then
                $array[$iIndex][1] = "DVD"
            Else
                $array[$iIndex][1] = "Blu"
            EndIf
            If GUICtrlRead($Checkbox1) = 1 Then
                $array[$iIndex][2] = "Delete"
            Else
                $array[$iIndex][2] = ""
            EndIf
            $array[$iIndex][3] = GUICtrlRead($Label)
            $array[$iIndex][4] = GUICtrlRead($dest)
        Case $load
            ; Read selection
            $sSelectedFolder = GUICtrlRead($List1)
            ; Find position in array
            $iIndex = _ArraySearch($array, $sSelectedFolder)
            ; Now set the various controls to the state saved in the array
            If $array[$iIndex][1] = "DVD" Then
                GUICtrlSetState($Radio1, $GUI_CHECKED)
                GUICtrlSetState($Radio2, $GUI_UNCHECKED)
            Else
                GUICtrlSetState($Radio1, $GUI_UNCHECKED)
                GUICtrlSetState($Radio2, $GUI_CHECKED)
            EndIf
            If $array[$iIndex][2] = "Delete" Then
                GUICtrlSetState($Checkbox1, $GUI_CHECKED)
            Else
                GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
            EndIf
            GUICtrlSetData($Label, $array[$iIndex][3])
            GUICtrlSetData($dest, $array[$iIndex][4])

    EndSwitch

WEnd

Func _addarray()

    ; Increase count and redim array
    $num = $num + 1
    ReDim $array[$num][5]
    ; Get new folder and add to array
    $sFolder = FileSelectFolder("Select ROOT folder.", "", 4)
    $array[$num - 1][0] = $sFolder
    $array[$num - 1][1] = "DVD"
    ; Clear list and reload
    $sListData = "|"
    For $i = 0 To $num - 1
        $sListData &= $array[$i][0] & "|"
    Next
    GUICtrlSetData($List1, $sListData)

EndFunc   ;==>_addarray

Func _clear()

    GUICtrlSetData($List1, "|")
    Global $array[1][5]
    $num = 0

EndFunc   ;==>_clear

Good luck with the rest of the project! :(

M23

Edit: Typnig!

thank you so much! ill give it a go.
Link to comment
Share on other sites

  • Moderators

bobbintb,

Just make a click on the list act like pressing the "Load" button by adding it to the same Case statement:

Case $load, $List1

It really is that simple. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

bobbintb,

From the Help file for GUICtrlCreateList:

style default: $LBS_SORT, $WS_BORDER, $WS_VSCROLL

So you need to create the ListBox without the $LBS_SORT style like this:

$List1 = GUICtrlCreateList($array, 8, 8, 505, 409, BitOR($WS_BORDER, $WS_VSCROLL))

Note that if you specify any styles for a control, you override any default or pre-existing styles. So make sure you add back in those you want to keep. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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