Jump to content

IniRead, GUICtrlSetImage, Run and other.


AlmarM
 Share

Recommended Posts

Hi,

Im working on my lastest project 'Desktop Tool'. And I need some help here :P

This is my program so far:

Global Const $BS_ICON = 0x0040
Global Const $BS_PUSHLIKE = 0x1000
Global Const $ES_READONLY = 2048
Global Const $CD_VOLUME = DriveGetLabel("C:\")
Global Const $CD_SERIAL = DriveGetSerial("C:\")
Global Const $CD_TOTAL = DriveSpaceTotal("C:\")
Global Const $CD_FREE = DriveSpaceFree("C:\")
Global Const $CD_SYSTEMTYPE = DriveGetFileSystem("C:\")
Global Const $CD_STATUS = DriveStatus("C:\")

_Menu()

Func _Menu()
    $GUI = GUICreate("Menu~", 170, 165, -1, -1)
    $ApplicationLauncher = GUICtrlCreateButton("Application Launcher", 10, 10, 150)
    $ComputerInformation = GUICtrlCreateButton("Computer Information", 10, 40, 150)
    $MouseInformation = GUICtrlCreateButton("Mouse Information", 10, 70, 150)
    $Hexing = GUICtrlCreateButton("Hexing", 10, 100, 150)
    $Homepage = GUICtrlCreateButton("AutoIt Homepage", 10, 130, 150)

    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $ApplicationLauncher
            GUIDelete($GUI)
            _AppLauncher()
        Case $nMsg = $ComputerInformation
            _ComInfo()
        Case $nMsg = $MouseInformation
            _MouseInfo()
        Case $nMsg = $Hexing
            _Hexing()
        Case $nMsg = $Homepage
            _Homepage()
        EndSelect
    WEnd
EndFunc

Func _AppLauncher()
    $GUI = GUICreate("Application Launcher~", 130, 325, -1, -1)
    GUICtrlCreateGroup("Applications", 10, 10, 110, 270)
    $Button1 = GUICtrlCreateButton("", 20, 30, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button2 = GUICtrlCreateButton("", 20, 80, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button3 = GUICtrlCreateButton("", 20, 130, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button4 = GUICtrlCreateButton("", 20, 180, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button5 = GUICtrlCreateButton("", 20, 230, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button6 = GUICtrlCreateButton("", 70, 30, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button7 = GUICtrlCreateButton("", 70, 80, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button8 = GUICtrlCreateButton("", 70, 130, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button9 = GUICtrlCreateButton("", 70, 180, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button10 = GUICtrlCreateButton("", 70, 230, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $ReturnMenu = GUICtrlCreateButton("Return to Menu", 10, 290, 110)
    If FileExists("C:\temp\$~settings.ini") Then
        $Read_Ini1 = IniRead("C:\temp\$~settings.ini", "AppLauncher", "Button1", "Not Found")
        GUICtrlSetImage($Button1, $Read_Ini1, 1)
    EndIf
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Button1
            $fod_Button1 = FileOpenDialog("Select a File", @DesktopDir, "Executeable's (*.exe)", 3, "", $GUI)
            If @error = 1 Then
            Else
                GUICtrlSetImage($Button1, $fod_Button1, 1)
                IniWrite("C:\temp\$~settings.ini", "AppLauncher", "Button1", $fod_Button1)
            EndIf
        EndSelect
    WEnd
EndFunc

If the user presses a button, it sould open a FileOpenDialog. When the users presses OK, the icon of the .exe is set on the button and the path is writed in a .ini (C:\temp\$~settings.ini). When the person starts the program again it sould read the ini for the selected paths. Until now all is working

What I want.

If the script readed the ini and set the button to the readed path. It sould launch the .exe the user selected and not open a filedialog again.

Hope you understand ^^,

AlmarM

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

You again :P

how about something like:

Case $nMsg = $Button1
    If FileExists("C:\temp\$~settings.ini") And $Read_Ini1 <> "Not Found" Then
        Run($Read_Ini1)
    Else
        $fod_Button1 = FileOpenDialog("Select a File", @DesktopDir, "Executeable's (*.exe)", 3, "", $GUI)
        If @error = 0 Then
            GUICtrlSetImage($Button1, $fod_Button1, 1)
            IniWrite("C:\temp\$~settings.ini", "AppLauncher", "Button1", $fod_Button1)
        EndIf
    EndIf
;...

If and Else were wrong in my previous code-posting (without the code-quotes), but now it should fit your needs.

You should probably use an array instead of "$Read_Ini1".

cheers

Edited by Mojo
You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

YAAAAAAAAAAAAY,

I did it for $Button1 :P

Global Const $BS_ICON = 0x0040
Global Const $BS_PUSHLIKE = 0x1000
Global Const $ES_READONLY = 2048
Global Const $CD_VOLUME = DriveGetLabel("C:\")
Global Const $CD_SERIAL = DriveGetSerial("C:\")
Global Const $CD_TOTAL = DriveSpaceTotal("C:\")
Global Const $CD_FREE = DriveSpaceFree("C:\")
Global Const $CD_SYSTEMTYPE = DriveGetFileSystem("C:\")
Global Const $CD_STATUS = DriveStatus("C:\")
Global $Button1_Found = 0, $Button2_Found = 0, $Button3_Found = 0, $Button4_Found = 0, $Button5_Found = 0
Global $Button6_Found = 0, $Button7_Found = 0, $Button8_Found = 0, $Button9_Found = 0, $Button10_Found = 0

_Menu()

Func _Menu()
    $GUI = GUICreate("Menu~", 170, 165, -1, -1)
    $ApplicationLauncher = GUICtrlCreateButton("Application Launcher", 10, 10, 150)
    $ComputerInformation = GUICtrlCreateButton("Computer Information", 10, 40, 150)
    $MouseInformation = GUICtrlCreateButton("Mouse Information", 10, 70, 150)
    $Hexing = GUICtrlCreateButton("Hexing", 10, 100, 150)
    $Homepage = GUICtrlCreateButton("AutoIt Homepage", 10, 130, 150)

    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $ApplicationLauncher
            GUIDelete($GUI)
            _AppLauncher()
        Case $nMsg = $ComputerInformation
            _ComInfo()
        Case $nMsg = $MouseInformation
            _MouseInfo()
        Case $nMsg = $Hexing
            _Hexing()
        Case $nMsg = $Homepage
            _Homepage()
        EndSelect
    WEnd
EndFunc

Func _AppLauncher()
    $GUI = GUICreate("Application Launcher~", 130, 325, -1, -1)
    GUICtrlCreateGroup("Applications", 10, 10, 110, 270)
    $Button1 = GUICtrlCreateButton("", 20, 30, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button2 = GUICtrlCreateButton("", 20, 80, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button3 = GUICtrlCreateButton("", 20, 130, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button4 = GUICtrlCreateButton("", 20, 180, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button5 = GUICtrlCreateButton("", 20, 230, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button6 = GUICtrlCreateButton("", 70, 30, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button7 = GUICtrlCreateButton("", 70, 80, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button8 = GUICtrlCreateButton("", 70, 130, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button9 = GUICtrlCreateButton("", 70, 180, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $Button10 = GUICtrlCreateButton("", 70, 230, 40, 40, $BS_ICON + $BS_PUSHLIKE)
    $ReturnMenu = GUICtrlCreateButton("Return to Menu", 10, 290, 110)
    
    If FileExists("C:\temp\$~settings.ini") Then
        $IniRead1 = IniRead("C:\temp\$~settings.ini", "AppLauncher", "Button1", "Not Found")
        GUICtrlSetImage($Button1, $IniRead1, 1)
        $Button1_Found = 1
    EndIf
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Button1
            If $Button1_Found = 1 Then
                ShellExecute($IniRead1)
            Else
                $fod_Button1 = FileOpenDialog("Select a file", @DesktopDir, "Executeable's (*.exe)", 3, "", $GUI)
                If @error = 1 Then
                Else
                    IniWrite("C:\temp\$~settings.ini", "AppLauncher", "Button1", $fod_Button1)
                    GUICtrlSetImage($Button1, $fod_Button1, 1)
                EndIf
            EndIf
        EndSelect
    WEnd
EndFunc

EDIT:

Now I need to fix this for al the buttons >.<

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

nice! :P

I personally would not use those additional vars $Button1_found, $Button2_found, etc.

but rather check ...

If $iniRead[$i] <> "Not Found" Then

ShellExecute($iniRead[$i])

Else

....

EndIf

This way you'll have lesser vars and ShellExecute will never try to run a program called "Not Found", should that ever be the case.

I hope you understand what I mean.

Additionaly, maybe with OnEvent the script doesn't have to do anything while in the loop, which might spare some cpu usage.

IF you want to switch to OnEvent it might be easier to implement right now, while the code is not THAT big yet.

greetz

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

Can you help me on $Button2 then?

If I know $Button2, I could easly do $Button3 - 10

AlmarM

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Can you help me on $Button2 then?

If I know $Button2, I could easly do $Button3 - 10

AlmarM

lol

sorry, maybe later when I'm at home. - I'll be leaving my office in a few minutes.

Until then, you might just have it working already. But I'll see if I find some time later to check by on the forums.

For starters, check the Help File for radio controls, there is a good example which you could use and modify.

It creates and checks several radio buttons in loops.

greetz

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

Well, Ok. And I found another problem :P

If I press $Button1 and select the file.

Then Press $Button1 again. It crashes. Saying $IniRead1 isnt declared.

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Well, Ok. And I found another problem :(

If I press $Button1 and select the file.

Then Press $Button1 again. It crashes. Saying $IniRead1 isnt declared.

AlmarM

Hi, are you still working on it? Or is it done already?

Cause I have my version up and running ... :P

???

Well, here's mine...

Global Const $BS_ICON = 0x0040
Global Const $BS_PUSHLIKE = 0x1000
Global Const $ES_READONLY = 2048
Global Const $CD_VOLUME = DriveGetLabel("C:\")
Global Const $CD_SERIAL = DriveGetSerial("C:\")
Global Const $CD_TOTAL = DriveSpaceTotal("C:\")
Global Const $CD_FREE = DriveSpaceFree("C:\")
Global Const $CD_SYSTEMTYPE = DriveGetFileSystem("C:\")
Global Const $CD_STATUS = DriveStatus("C:\")
Global $aHButtons[10], $IniRead[10]

$GUI = GUICreate("Menu~", 170, 165, -1, -1)
$ApplicationLauncher = GUICtrlCreateButton("Application Launcher", 10, 10, 150)
$ComputerInformation = GUICtrlCreateButton("Computer Information", 10, 40, 150)
$MouseInformation = GUICtrlCreateButton("Mouse Information", 10, 70, 150)
$Hexing = GUICtrlCreateButton("Hexing", 10, 100, 150)
$Homepage = GUICtrlCreateButton("AutoIt Homepage", 10, 130, 150)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Select
    Case $nMsg = -3
        Exit
    Case $nMsg = $ApplicationLauncher
        GUIDelete($GUI)
        _AppLauncher()
;~   Case $nMsg = $ComputerInformation
;~       _ComInfo()
;~   Case $nMsg = $MouseInformation
;~       _MouseInfo()
;~   Case $nMsg = $Hexing
;~       _Hexing()
;~   Case $nMsg = $Homepage
;~       _Homepage()
    EndSelect
WEnd

Func _AppLauncher()
    $GUI = GUICreate("Application Launcher~", 130, 325, -1, -1)
    GUICtrlCreateGroup("Applications", 10, 10, 110, 270)
    
    Local $left = 20, $top = 30
    For $i = 0 To UBound($aHButtons)-1
        $aHButtons[$i] = GUICtrlCreateButton("", $left, $top, 40, 40, $BS_ICON + $BS_PUSHLIKE)
        $top += 50
        If $i == 4 Then
            $left = 70
            $top = 30
        EndIf
    Next
    $ReturnMenu = GUICtrlCreateButton("Return to Menu", 10, 290, 110)
    
    If FileExists("C:\temp\$~settings.ini") Then
        For $i = 0 To UBound($aHButtons)-1
            $IniRead[$i] = IniRead("C:\temp\$~settings.ini", "AppLauncher", "Button"&$i, "Not Found")
            If $IniRead[$i] <> "Not Found" Then GUICtrlSetImage($aHButtons[$i], $IniRead[$i], 1)
        Next
    EndIf
    
    GUISetState()
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case -3
                Exit
            Case $aHButtons[0] To $aHButtons[UBound($aHButtons)-1]
                For $i = 0 To UBound($aHButtons)-1
                    If $aHButtons[$i] == $nMsg Then
                        $IniRead[$i] = IniRead("C:\temp\$~settings.ini", "AppLauncher", "Button"&$i, "Not Found")
                        If FileExists("C:\temp\$~settings.ini") And $IniRead[$i] <> "Not Found" Then
                            ShellExecute($IniRead[$i])
                        Else
                            $fod_Button = FileOpenDialog("Select a file", @DesktopDir, "Executeable's (*.exe)", 3, "", $GUI)
                            If Not @error Then
                                IniWrite("C:\temp\$~settings.ini", "AppLauncher", "Button"&$i, $fod_Button)
                                GUICtrlSetImage($aHButtons[$i], $fod_Button, 1)
                            EndIf
                        EndIf
                    EndIf
                Next
        EndSwitch
    WEnd
EndFunc

I had to comment out some of your code, cause those functions weren't in the script.

Test it and let me know if it works for you aswell.

I'm out now, but will be back in the forums sometime tomorrow.

cu

cheers

EDIT: slightly changed the code (array) -> first Button will be "Button0" !

Edited by Mojo
You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

Whos the man?

YOUR THE MAN.

Only one thing :P

Case $aHButtons[0] To $aHButtons[UBound($aHButtons)-1]
Case $aHButtons[0] ^ ERROR

Dont know how to fix this :(

AlmarM

EDIT:

Oops forgot to post this:

Illegal text at the end of statement (one statement per line).:
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Whos the man?

YOUR THE MAN.

Only one thing :(

Case $aHButtons[0] To $aHButtons[UBound($aHButtons)-1]
Case $aHButtons[0] ^ ERROR

Dont know how to fix this :idea:

AlmarM

EDIT:

Oops forgot to post this:

Illegal text at the end of statement (one statement per line).:
Hi again :P

maybe that's a version problem. I'm using 3.2.12.0.

From the help file:

Switch...Case...EndSwitch

Switch <expression>

Case <value> [To <value>] [,<value> [To <value>] ...]

statement1

...

[Case <value> [To <value>] [,<value> [To <value>] ...]

statement2

...]

[Case Else

statementN

...]

EndSwitch

... you see?

What version are you using?

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

...there you go. :P

I noticed one other tiny thing:

if the folder 'C:\temp' does not exist, the file doesn't get written and this results in weird behavior.

-> Exe re-select over and over again on clicking a button.

Might wanna add some checking if the folder exists and else create it, maybe even create an empty ini file to see if you got proper write access.

(not relevant for C:\temp, cause most users can write to that, IF it exists, but should you consider writing the inifile into any other folder than temp....)

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
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...