Sign in to follow this  
Followers 0
christiancdj

Execute files from Array

8 posts in this topic

how can i run the files in the list from the array?

i got a list of files to install, but i dont get all files i always get the last dropped file to the array - what goes wrong?

how can i install all droped files to the list?

#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <File.au3>
#include <Array.au3>
#include <file.au3>


Global $gaDropFiles[1], $iDropItem = -1
Global $WM_DROPFILES = 0x233
Global $hFile

GUICreate(" My GUI acceptfile", 620, 320, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
$file = GUICtrlCreateButton("Install", 10, 5, 300, 40)
$mylist = GUICtrlCreateList("", 10, 54, 441, 253, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
GUICtrlSetState($mylist, $GUI_DROPACCEPTED)
GUISetState()
GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES_FUNC')

Global $Array

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_DROPPED

        Dim $sPath = _ArrayToString($gaDropFiles, "")
        GUICtrlSetData($mylist,$sPath)

    Case $file
        daisyChainRun()

    EndSwitch
WEnd




Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', 0xFFFFFFFF, 'ptr', 0, 'int', 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', 0, 'int', 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate('wchar[' & $nSize & ']')
        DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', DllStructGetPtr($pFileName), 'int', $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_FUNC

func daisyChainRun(); will be used to run selected scripts after they are properly sorted etc


For $i = 1 To $gaDropFiles[0]
    RunWait(@ComSpec & " /c " & $gaDropFiles[$i] & " >> log.txt")

Next


EndFunc

Share this post


Link to post
Share on other sites



christiancdj,

It is much easier to let AutoIt do the hard work for you - like this: ;)

#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
#include <file.au3>

Global $gaDropFiles[1] = [0]

GUICreate(" My GUI acceptfile", 620, 320, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES

$file = GUICtrlCreateButton("Install", 10, 5, 300, 40)
$mylist = GUICtrlCreateList("", 10, 54, 441, 253, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
GUICtrlSetState($mylist, $GUI_DROPACCEPTED)

GUISetState()


While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_DROPPED
            ; Add file to list
            GUICtrlSetData($mylist, @GUI_DragFile) ; No need for the handler - AutoIt gets the path & name for you <<<<<<<<<<
            ; Add file to array
            $gaDropFiles[0] += 1
            ReDim $gaDropFiles[$gaDropFiles[0] + 1]
            $gaDropFiles[$gaDropFiles[0]] = @GUI_DragFile
        Case $file
            daisyChainRun()

    EndSwitch
WEnd

Func daisyChainRun(); will be used to run selected scripts after they are properly sorted etc

    For $i = 1 To $gaDropFiles[0]
        ;RunWait(@ComSpec & " /c " & $gaDropFiles[$i] & " >> log.txt")
        ConsoleWrite(@ComSpec & " /c " & $gaDropFiles[$i] & " >> log.txt" & @CRLF)
    Next

EndFunc   ;==>daisyChainRun

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

wow thanks a lot, didn't know the funktion but now i got a new problem_

im realy confused - how can i move the files order up and down or even throw one out of the list?

i realy dont know how @GUI_DragFile works, sorry

Share this post


Link to post
Share on other sites

i realy dont know how @GUI_DragFile works

It has nothing to do with @GUI_DragFile - that just gets the filename into the list and array. What you need to do is manipulate the array and then redraw the list. :)

I have added 3 buttons. The "Up" and "Delete" buttons work - I leave it to you to write the code for the "Down" button (Hint: look at the "Up" code). :idiot:

#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
#include <file.au3>

Global $gaDropFiles[1] = [0]

GUICreate(" My GUI acceptfile", 620, 320, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES

$file = GUICtrlCreateButton("Install", 10, 5, 300, 40)
$mylist = GUICtrlCreateList("", 10, 54, 441, 253, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_EXTENDEDSEL))
GUICtrlSetState($mylist, $GUI_DROPACCEPTED)

$hUp_Button = GUICtrlCreateButton("Up", 470, 54, 80, 30)
$hDown_Button = GUICtrlCreateButton("Down", 470, 277, 80, 30)
$hDel_Button = GUICtrlCreateButton("Delete", 470, 165, 80, 30)

GUISetState()


While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_DROPPED
            ; Add file to list
            GUICtrlSetData($mylist, @GUI_DragFile) ; No need for the handler - AutoIt gets the path & name for you <<<<<<<<<<
            ; Add file to array
            $gaDropFiles[0] += 1
            ReDim $gaDropFiles[$gaDropFiles[0] + 1]
            $gaDropFiles[$gaDropFiles[0]] = @GUI_DragFile
        Case $file
            daisyChainRun()
        Case $hUp_Button
            $aIndex = _GUICtrlListBox_GetSelItems($mylist)
            If $aIndex[0] = 1 Then
                ; Check if aleady at top
                If $aIndex[1] <> 0 Then
                    ; Swap elements
                    _ArraySwap($gaDropFiles[$aIndex[1]], $gaDropFiles[$aIndex[1] + 1])
                    ; Destroy list
                    GUICtrlSetData($mylist, "")
                    ; Rewrite list
                    For $i = 1 To $gaDropFiles[0]
                        GUICtrlSetData($mylist, $gaDropFiles[$i])
                    Next
                EndIf
            EndIf

        Case $hDown_Button

        Case $hDel_Button
            $aIndex = _GUICtrlListBox_GetSelItems($mylist)
            If $aIndex[0] = 1 Then
                ; Remove form array and lower count
                _ArrayDelete($gaDropFiles, $aIndex[1] + 1)
                $gaDropFiles[0] -= 1
                ; Destroy list
                GUICtrlSetData($mylist, "")
                ; Rewrite list
                For $i = 1 To $gaDropFiles[0]
                    GUICtrlSetData($mylist, $gaDropFiles[$i])
                Next
            EndIf

    EndSwitch
WEnd

Func daisyChainRun(); will be used to run selected scripts after they are properly sorted etc

    For $i = 1 To $gaDropFiles[0]
        ;RunWait(@ComSpec & " /c " & $gaDropFiles[$i] & " >> log.txt")
        ConsoleWrite(@ComSpec & " /c " & $gaDropFiles[$i] & " >> log.txt" & @CRLF)
    Next

EndFunc   ;==>daisyChainRun

All clear? Please ask if not. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thanks

your are a genius :)

thanks a lot

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i got no idea why its not working, please help

cant move down objts

$aIndex = _GUICtrlListBox_GetSelItems($mylist)
            If $aIndex[0] = 1 Then
;~
                ; Check if aleady at top
                If $aIndex[1] <> 0 Then
;~
                    ; Swap elements
                    _ArraySwap($gaDropFiles[$aIndex[1]+1], $gaDropFiles[$aIndex[1]])
                    _ArrayDisplay($mylist)
                    ; Destroy list
                    GUICtrlSetData($mylist, "")

                    ; Rewrite list
                    For $i = 1 To $gaDropFiles[0]
                        GUICtrlSetData($mylist, $gaDropFiles[$i])
                    Next
;~                 EndIf
                EndIf
            EndIf
Edited by christiancdj

Share this post


Link to post
Share on other sites

christiancdj,

You were supposed to base the code on the "Up" code, not copy it! ;)

You need to change 2 things to get it to work:

- 1. You need to check if the item is at the bottom, not the top - look at the <<<<<<<<< 1 line

- 2. Because the array is 1-based and the list is 0-based you need to adjust the elements to swap - look at the <<<<<<<<< 2 line

$aIndex = _GUICtrlListBox_GetSelItems($mylist)
If $aIndex[0] = 1 Then
     ; Check if aleady at bottom
     If $aIndex[1] <> $gaDropFiles[0] - 1 Then ; <<<<<<<<<<<<<<<<<<<< 1
         ; Swap elements
         _ArraySwap($gaDropFiles[$aIndex[1] + 1], $gaDropFiles[$aIndex[1] + 2]) ; <<<<<<<<<<<<<<<<<<<< 2
         ; Destroy list
         GUICtrlSetData($mylist, "")
         ; Rewrite list
         For $i = 1 To $gaDropFiles[0]
             GUICtrlSetData($mylist, $gaDropFiles[$i])
         Next
     EndIf
EndIf

Do you understand the 0-based vs 1-based point? Ask if not, it is quite important when you deal with arrays and indices. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

got nothing to say you are a god

thanks again it got it now :)

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