Sign in to follow this  
Followers 0
Achilles

_GetFilesDropped function I'm trying to write

2 posts in this topic

#1 ·  Posted (edited)

I decided it would be useful to have a _GetFilesDropped() function that gets all the files you drop into your GUI. It's not working very well though... It can get the selected Indices of items if they're on the desktop but not if they're in folders. It can get the text of multiple items...

Anybody have any ideas to help finish it?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#Include <GuiListView.au3>
#Include <Array.au3>

Opt("GUIOnEventMode", 1)

GUICreate("listview items", 420, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
    GUISetOnEvent($GUI_EVENT_DROPPED, '_FilesDropped')

$input1 = GUICtrlCreateInput("", 10, 20, 400, 100)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)  ; to allow drag and dropping

GUISetState()


While 1 
    Sleep(200) 
Wend 

Func _FilesDropped()
    $array = _GetFilesDropped()
    
    _ArrayDisplay($array) 
EndFunc 

Func _GetFilesDropped()
    
    $file = @GUI_DragFile
    
    $folder = _GetFileFolder($file)
    
    $path = _GetFilePath($file) 
    
;~  Msgbox(0, 'File info', '_IsFile() = ' & _IsFile($file) & @CRLF & '$file = ' & $file & @CRLF & '$folder = ' & $folder & @CRLF & '$path = ' & $path)
    
    If WinExists($folder) then 
        $tempHandle = WinGetHandle($folder) 
    Else 
        $tempHandle = ControlGetHandle(ControlGetHandle('[Class:Progman]', '', '[Class:SHELLDLL_DefView]'), '', '[Class:SysListView32;Instance:1]')
    EndIf
    
    $array = _GUICtrlListView_GetSelectedIndices($tempHandle, True)
    _ArrayDisplay($array, 'Selected items')
    For $i = 1 to $array[0] 
        $temp = _GUICtrlListView_GetItemTextArray($tempHandle, $array[$i])
        _ArrayDisplay($temp, 'Item ' & $i & ' info')
        $array[$i] = $path & '\' & _GUICtrlListView_GetItemText($tempHandle, $array[$i], 0)
    Next 
    
    Return $array   
EndFunc 

Func _IsFile($path)
    Return StringInStr(FileGetAttrib($path), "D") = 0 
EndFunc

Func _GetFileFolder($path) 
    $temp = StringSplit($path, '\') 
    Return $temp[$temp[0] - 1]
EndFunc

Func _GetFilePath($file) 
    $temp = StringSplit($file, '\') 
    $text = ''
    For $i = 1 to $temp[0] - 1
        $text &= $temp[$i] & '\' 
    Next 
    Return StringTrimRight($text, 1) 
EndFunc

Func _Exit()
    Exit 
EndFunc
Edited by Achilles

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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