Jump to content

Create checkbox base on entry in ini file.


Go to solution Solved by Malkey,

Recommended Posts

Any one can advise me how to create checkbox for entry base on ini information.

For example, if my ini file has entry like this.

 
[block]
Key1=side1
Key2=side2
 
How can I create checkbox for these and be able to read the each checkbox value/status? The information in ini is not fixed so sometimes there may be more than 2 entry. I not sure how I can assign variable to GUICtrlCreateCheckbox() base on the information in ini file. TIA
 
Sample below.
 
#include <GUIConstantsEx.au3>
Local $msg
$counter = 0

GUICreate("My GUI Checkbox")

While 1
    $counter = $counter+1
    $Sidename = IniRead("side.ini", "Block", "Key" & $counter, "End")
    If $Sidename = "End" Then
        $counter = $counter-1
        ExitLoop
    EndIf
    GUICtrlCreateCheckbox($Sidename, 10, (($counter*30)-10), 120, 20)
WEnd
$Button1 = GUICtrlCreateButton("Submit", 15, 100, 73, 30)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $Button1
        ; Code to process the checkbox information.

    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
WEnd
 
Link to comment
Share on other sites

You can create an array to store the IDs of the checkboxes

Pseudocode :

Local $cb[100], $counter = 0

GUICreate("My GUI Checkbox")
While 1
    ;....
    $cb[$counter] = GUICtrlCreateCheckbox(....)
    $counter += 1
WEnd
Redim $cb[$counter]
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $Button1
       ; get infos using GuiCtrlRead or else by looping through the $cb array 
    EndSwitch
WEnd
Link to comment
Share on other sites

  • Solution

Using this "side.ini" ini file:-

[Block]
Key1=side1
Key2=side2
Key3=side3
Key4=side4
Key5=side5
Key6=side6
Key7=side7
Key8=side8
Key9=side9
Key10=side10
Key11=side11
Key12=side12
Key13=side13
Key14=side14
Key15=side15
Key16=side16
Key17=side17
Key18=side18
Key19=side19
Key20=side20
Key21=side21
Key22=side22
Key23=side23
Key24=side24
Key25=side25
Key26=side26

with this example:-

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

Local $msg, $sResults
Local $counter = 0
Local $aIdCB[1000]
GUICreate("My GUI Checkbox")

While 1
    $counter += 1
    $Sidename = IniRead("side.ini", "Block", "Key" & $counter, "End")
    If $Sidename = "End" Then
        $counter -= 1
        ExitLoop
    EndIf
    $aIdCB[$counter - 1] = GUICtrlCreateCheckbox($Sidename, ((Ceiling($counter / 12) - 1) * 125) + 10, (((Mod($counter - 1, 12)) * 30) + 10), 120, 20)
WEnd
ReDim $aIdCB[$counter]
$Button1 = GUICtrlCreateButton("Submit", 255, 100, 73, 30)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button1
            ; Code to process the checkbox information.
            For $i = 0 To $counter - 1
                $sResults &= ControlGetText("My GUI Checkbox", "", $aIdCB[$i]) & " is checked - " & (BitAND(GUICtrlRead($aIdCB[$i]), $GUI_CHECKED) = $GUI_CHECKED) & @CRLF
            Next
            MsgBox(0, "CheckBox Results", $sResults)
            $sResults = ""
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

What about this?

#include <GUIConstantsEx.au3>
Local $GUI, $mouse, $msg, $CheckVar, $i, $Sidename
$counter = 0
$GUI = GUICreate("My GUI Checkbox")
$Button1 = GUICtrlCreateButton("Submit", 15, 140, 73, 30)
GUISetState()

Pop()

Func Pop()
    Do
    $counter = $counter+1
    ConsoleWrite('$counter '& $counter &@CRLF)
    $Sidename = IniRead("side.ini", "Block", "Key" & $counter, "End")
    If $Sidename <> 'End' Then
        GUICtrlCreateCheckbox($Sidename, 10, (($counter*20)-10), 80, 20)
    EndIf
    Until $Sidename = 'End'
EndFunc

While 1
    $ID = $counter+1
    Sleep(50)
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button1
        ;=================
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    $mouse = GUIGetCursorInfo($GUI)
    If $mouse[2] = 1 Then
        ConsoleWrite('$mouse[4] '& $mouse[4] &@CRLF)
        $ID = $mouse[4]-3
        ConsoleWrite('$ID '& $ID &@CRLF)
        If $mouse[4] >= 4 Then
        $CheckVar = GUICtrlRead($mouse[4])
        If $CheckVar = 4 Then
        IniWrite("side.ini", 'Block', 'Key'&$ID&'State', 1)
        ElseIf $CheckVar = 1 Then
        IniWrite("side.ini", 'Block', 'Key'&$ID&'State', 0)
        EndIf
        EndIf
    EndIf
WEnd

mouse primary down gives id, use id to read if checkbox ticked or not, write to ini accordingly.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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