Sign in to follow this  
Followers 0
jvanegmond

IniWrite backfires on me

5 posts in this topic

Here's the short example of my code, which works fine...

Global $button[100][100][2]

$x = 0
$y = 0
$button[$x][$y][1] = "C:\Program Files\MSN Messenger\msnmsgr.exe"

IniWrite(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1])

Here's real code in which it obviously does NOT work. hat's going on here, i'm using it correctly, i think. Line 74 !

#include <GUIConstants.au3>

;Change these variables only
Global $buttonsize = 30; Mind your resolution with this one.
Global $iconsize = 0; 1 for big icon image 0 for small icon image
; If you change one of the two following variables to a smaller value then some icons may be lost.
Global $buttonrow = 3; minimum 3 !
Global $buttoncol = 6
;EndChange

Global $GUI[2] = [$buttonsize * ($buttonrow + 1), $buttonsize * ($buttoncol + 2)]
Global $Visible
Global $button[$buttonrow][$buttoncol][2]

For $y = 0 to $buttoncol - 1
    For $x = 0 to $buttonrow - 1
        $button[$x][$y][0] = -1
    Next
Next

Opt("RunErrorsFatal", 0)

Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetIcon( "shell32.dll" , 43 )
TraySetOnEvent(-7, "ShowHide")

$Filehandle = FileOpen("Menu.ini", 1)

GUICreate("Quick Launch Menu", $GUI[0], $GUI[1], @DesktopWidth - $GUI[0], @DesktopHeight - $GUI[1] - 30, $WS_POPUP, $WS_EX_TOOLWINDOW)
WinSetOnTop("Quick Launch Menu", "", 1)

$New = GUICtrlCreateButton("", 10, 10, $buttonsize, $buttonsize , $BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",54, $iconsize)
$Delete = GUICtrlCreateButton("", 10 + $buttonsize, 10, $buttonsize, $buttonsize , $BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",131, $iconsize)
$Close = GUICtrlCreateButton("", 10 + (2 * $buttonsize), 10, $buttonsize, $buttonsize, $BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",27, $iconsize)

If FileExists(@ScriptDir & "Menu.ini") Then
    For $y = 0 to $buttoncol - 1
        For $x = 0 to $buttonrow - 1
            $button[$x][$y][1] = IniRead(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y, "Path", "")
            If $button[$x][$y][1] <> "" Then
                $button[$x][$y][0] = GUICtrlCreateButton("", 10 + ( $x * $buttonsize ), 15 + $buttonsize + ( $y * $buttonsize ), $buttonsize, $buttonsize, $BS_ICON)
                GUICtrlSetImage(-1, $button[$x][$y][1], 0, $iconsize)
            EndIf
        Next
    Next
EndIf

;ShowHide();uncomment this to show at startup

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Close
            Exit
        Case $msg = $New
            ;Search for a empty place to put the button in.
                For $y = 0 to $buttoncol - 1
                    For $x = 0 to $buttonrow - 1
                        If $button[$x][$y][0] = -1 Then
                            $button[$x][$y][1] = FileOpenDialog("Create Shortcut to:", "C:\", "Executables (*.exe;*.bat)")
                            If @error Then
                            ;User didn't pick a file
                            Else
                            ; This is for test purposes
                                $button[$x][$y][1] = Inputbox("Title", "$button[$x][$y][1] before writing in the ini", $button[$x][$y][1])
                                
                            ; It often doesn't write!! help me!
                            ; PROBLEMS HERE
                                IniWrite(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1]);Big issues here!
                            ; PROBLEMS END HERE
                            ; Attention
                                
                                $button[$x][$y][0] = GUICtrlCreateButton("", 10 + ( $x * $buttonsize ), 15 + $buttonsize + ( $y * $buttonsize ), $buttonsize, $buttonsize, $BS_ICON)
                                GUICtrlSetImage (-1, "shell32.dll",2, $iconsize)
                                GUICtrlSetImage(-1, $button[$x][$y][1], 0, $iconsize)
                                
                                GUISetState(@SW_SHOW); Because it sometimes dissappears here for no apparent reason
                            EndIf
                            
                            ExitLoop 2
                        EndIf
                    Next
                Next
        Case $msg = $Delete
            While 1
                ToolTip("Click to delete"); updating it all the time so it follows your mouse
                $msg = GUIGetMsg()
                
                For $y = 0 to $buttoncol - 1
                    For $x = 0 to $buttonrow - 1
                        If $msg = $button[$x][$y][0] Then
                            GUICtrlDelete($button[$x][$y][0])
                            $button[$x][$y][0] = -1
                            IniDelete(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y)
                        EndIf
                    Next
                Next
                
                If $msg = $Delete Then
                    ExitLoop
                EndIf
                
            WEnd
            ToolTip("")
            $msg = GUIGetMsg()
    EndSelect
    For $y = 0 to $buttoncol - 1
        For $x = 0 to $buttonrow - 1
            If $msg = $button[$x][$y][0] Then
                Run($button[$x][$y][1])
            EndIf
        Next
    Next
Wend

Func ShowHide()
    If $Visible Then
        GUISetState(@SW_HIDE)
    Else
        GUISetState(@SW_SHOW)
    EndIf
    $Visible = NOT $Visible
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

this doesn't look right :

IniWrite(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1])

shouldn't that be:

IniWrite(@ScriptDir & "\Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1])

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

this doesn't look right :

IniWrite(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1])

shouldn't that be:

IniWrite(@ScriptDir & "\Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1])

I can't believe that..

When i was using _

IniWrite("Menu.ini", "Button=" & $x & ":" & $y, "Path", $button[$x][$y][1])

it didn't work either.

But thanks a lot for pointing this out! :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

also you create this at the start

$button[$x][$y]

then use

$button[$x][$y][1] = IniRead(@ScriptDir & "Menu.ini", "Button=" & $x & ":" & $y, "Path", "")

i would prefer

$button = IniReadSection(@ScriptDir & "Menu.ini", "Button=")

because that creates

$button[$x][$y]

i did something very similar... take a look

http://www.autoitscript.com/forum/index.ph...pic=25790&st=0#

You could use the SAME engine

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks Valuater, but i didn't mean to build a project as extensive as it already is. I just had nothing to do and i recon it would come in handy. I'm just going to set tooltips for every button and then i won't be working on it.

Thanks for the reply. :)

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  
Followers 0