Jump to content

1-st shortcut is missing from Array


au3scr
 Share

Recommended Posts

If you put 3 shortcuts in scriptdir , script will display only 2, whats wrong :S?

Edit ===>

Problem is here i think, but i dont know how solution it dont work if i set -1 to 0 or 1 or if i set 1 to 0 or 1

For $i = 1 To $FilesToArray[0] -1

Youcan test it by making some shortcuts in scriptdir and then running script.

if you set For $i = 1 To $FilesToArray[0] -1 to For $i = 1 To $FilesToArray[0] -2 then 2 sortcuts are missing.

<=== Edit

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>


#Region ### START Koda GUI section ### Form=
Global $FilesToArray = _FileListToArray(@ScriptDir, "*.lnk", 1)
Global $Shortcuts[$FilesToArray[0]]
$x = 0
$y = 36
$Form1 = GUICreate("Form1", 220, 447, 193, 125)
$Button2 = GUICtrlCreateButton("(Not allowed)", 260, 100, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON))
GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0)
For $i = 1 To $FilesToArray[0] - 1
    $file = FileGetShortcut(@ScriptDir & "\" & $FilesToArray[$i])
    $Shortcuts[$i] = GUICtrlCreateButton($FilesToArray[$i], 20, $y - 15, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON))
    $imgpath = $file[0]
    If StringRight($imgpath, 4) = ".exe" Then
        GUICtrlSetImage(-1, $imgpath, 0)
    Else
        ; use others

    EndIf
GUICtrlCreateLabel ($FilesToArray[$i],60,$y)
;~     $x = $x + 36
;~     If $x > 200 Then
        $y = $y + 36
;~         $x = 0
;~     EndIf
Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by au3scr
Link to comment
Share on other sites

Without testing, I think your problem may be here:

Global $FilesToArray = _FileListToArray(@ScriptDir, "*.lnk", 1)
Global $Shortcuts[$FilesToArray[0]]

By setting your $Shortcuts array to the size of the number in $FilesToArray[0] you have made an array that is 1 element smaller than you want it to be.

Try chaning it to this:

Global $FilesToArray = _FileListToArray(@ScriptDir, "*.lnk", 1)
Global $Shortcuts[$FilesToArray[0] + 1]

See how that works.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Just spotted, change this...

For $i = 1 To $FilesToArray[0] - 1

to this...

For $i = 1 To $FilesToArray[0]

:P

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

I tried, it dont work for me, i got solution, i created shortcut with name " zzzzzzzz" (1-st char i got when i hold down alt and typed 255)

:P

what you thhing about it? is it good or bad?

anyway thanx 4 ur quick replay :(

Edited by au3scr
Link to comment
Share on other sites

Try this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>


#Region ### START Koda GUI section ### Form=
Global $FilesToArray = _FileListToArray(@ScriptDir, "*.lnk", 1)
Global $Shortcuts[$FilesToArray[0] + 1]
$x = 0
$y = 36
$Form1 = GUICreate("Form1", 220, 447, 193, 125)
$Button2 = GUICtrlCreateButton("(Not allowed)", 260, 100, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON))
GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0)
For $i = 1 To $FilesToArray[0]
    $file = FileGetShortcut(@ScriptDir & "\" & $FilesToArray[$i])
    $Shortcuts[$i] = GUICtrlCreateButton($FilesToArray[$i], 20, $y - 15, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON))
    $imgpath = $file[0]
    If StringRight($imgpath, 4) = ".exe" Then GUICtrlSetImage(-1, $imgpath, 0)

    
    GUICtrlCreateLabel ($FilesToArray[$i],60,$y)
    
    $y = $y + 36

Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Any good?

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Thank you for your help, now next question, how i add actions for buttons if "case $Shortcuts[$i]" Dont work

I would like execute program when i click on button that has program's icon

your last reply helped me :P

Edited by au3scr
Link to comment
Share on other sites

I could show you how to add actions using OnEvent mode, but not with the GUIGetMsg way you're using.... I find OnEvent mode much more intuitive.

Here's an OnEvent way of doing it using your code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)


Global $FilesToArray = _FileListToArray(@ScriptDir, "*.lnk", 1)
Global $Shortcuts[$FilesToArray[0] + 1]
$x = 0
$y = 36
$Form1 = GUICreate("Form1", 220, 447, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")

$Button2 = GUICtrlCreateButton("(Not allowed)", 260, 100, 36, 36, BitOR($BS_PUSHBOX, $BS_FLAT, $BS_ICON))
GUICtrlSetImage(-1, "C:\windows\explorer.exe", 0)
For $i = 1 To $FilesToArray[0]
    $file = FileGetShortcut(@ScriptDir & "\" & $FilesToArray[$i])
    $Shortcuts[$i] = GUICtrlCreateButton($FilesToArray[$i], 20, $y - 15, 36, 36)
    GUICtrlSetOnEvent(-1,"clicked")
    
    $imgpath = $file[0]
    If StringRight($imgpath, 4) = ".exe" Then GUICtrlSetImage(-1, $imgpath, 0)

    GUICtrlCreateLabel ($FilesToArray[$i],60,$y)
    
    $y = $y + 36
Next

GUISetState(@SW_SHOW)

While 1
Sleep(100)
WEnd

Func clicked()
ShellExecute(GUICtrlRead(@GUI_CtrlId))
EndFunc

Func close()
    Exit
EndFunc
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
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...