Jump to content

Recommended Posts

Posted

Hi all guys,

I created several Menuitems inside a menu:

Global $CB_Curr[UBound($aCurr)]
$idFileMenu = GUICtrlCreateMenu("CryptoWatcher")
For $i = 1 to UBound($aCurr)-1
    $CB_Curr[$i] = GUICtrlCreateMenuItem($aCurr[$i],$idFileMenu)
Next

I would like to check/uncheck some of them (and save in my settings.ini) so that I can show a Tab that has info only for selected items.

Since I don't have a defined menuitem name but an array, how can I manage it? Through "case ..." seems not possible.

Thanks a lot,

Marco

 

Posted (edited)

I made a demo script once that used an INI file to create a checkbox list and saved the states which your post made me think of.

I did a quick and dirty tailor to make it work for a menu instead of CheckBox controls; try it out if you please:

  Reveal hidden contents
Edited by spudw2k
cleaned up tailored demo a little
Posted

Here is an example that is not "on event" mode.  
I didn't bother reading or writing to an ini file.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Example()


Func Example()
    GUICreate("My GUI menu", 300, 300)
    Local $sStatus = "Ready"
    Local $aCurr = [0, 1, 0, 1, 1, 0, 1, 0, 1, 1] ; 0 - checkbox unchecked, 1 - checkbox checked.
    Global $CB_Curr[UBound($aCurr)]
    $idFileMenu = GUICtrlCreateMenu("CryptoWatcher")
    For $i = 0 To UBound($aCurr) - 1
        $CB_Curr[$i] = GUICtrlCreateMenuItem("Check " & $i, $idFileMenu)
        ;ConsoleWrite($CB_Curr[$i] & @CRLF) ; Note the id numbers that were created
        If $aCurr[$i] Then
            GUICtrlSetState(-1, $GUI_CHECKED)
        EndIf
    Next

    Local $idBut = GUICtrlCreateButton("Display $aCurr Array", 50, 230, 130, 20)
    Local $idStatusLabel = GUICtrlCreateLabel($sStatus, 0, 265, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                Exit

            Case $CB_Curr[0] To $CB_Curr[UBound($aCurr) - 1]
                $iIndex = $Msg - $CB_Curr[0] ; Finds the index of $CB_Curr array (the Menu Item that was pressed)
                If BitAND(GUICtrlRead($CB_Curr[$iIndex]), $GUI_CHECKED) = $GUI_CHECKED Then
                    GUICtrlSetState($CB_Curr[$iIndex], $GUI_UNCHECKED)
                    GUICtrlSetState($idStatusLabel, $GUI_HIDE)
                    $aCurr[$iIndex] = 0 ; Update $aCurr
                Else
                    GUICtrlSetState($CB_Curr[$iIndex], $GUI_CHECKED)
                    GUICtrlSetState($idStatusLabel, $GUI_SHOW)
                    $aCurr[$iIndex] = 1 ; Update $aCurr
                EndIf
                
            Case $idBut
                _ArrayDisplay($aCurr)
        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Posted

Thanks @spudw2k and @Malkey!

Honestly i'd rather not using checkboxes (they need to be fitted in  MainGui or another Gui. 

And I found so interesting that

  On 5/23/2018 at 2:35 AM, Malkey said:

Case $CB_Curr[0] To $CB_Curr[UBound($aCurr) - 1]

Expand  

didn't know I could cycle trough them in  Case statement.

In this way I will populate a ListView containing only "checked" menuitems.

I still need to write this code but I'll do that today,

thanks again,

Marco

Posted

Keep in mind, that case statement works because the control IDs are contiguous.  If they were not created one after another then that case statement wouldn't work.  

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...