Jump to content
Sign in to follow this  
Floppy

FTP file manager

Recommended Posts

Floppy

Hi, I'm making a FTP file manager. I need help because I don't know how to show the file-type associated icon.

Here's my script:

#include <FTP_Ex.au3>
#Include <Array.au3>
#Include <File.au3>
#include <GuiConstants.au3>
#Include <GuiListView.au3>
#Include <GuiImageList.au3>


$ftp_open=_FTPOpen('myftp')
$gui=GUICreate('',500,400)
$list=GUICtrlCreateListView('File|Size',10,150,480,240)
_GUICtrlListView_SetColumnWidth($list,0,150)
GUISetState(@SW_SHOW,$gui)
$ftp_con=_FTPConnect($ftp_open,'host','username','password')

$get_dirs=_FTPFilesListToArray($ftp_con,1)
For $i1=1 To (UBound($get_dirs)-1)
    GUICtrlCreateListViewItem($get_dirs[$i1],$list)
    GUICtrlSetImage(-1,'shell32.dll',4,1)
Next

$get_files=_FTPFilesListToArray($ftp_con,2)
For $i2=1 To (UBound($get_files)-1)
    GUICtrlCreateListViewItem($get_files[$i2],$list)
Next


While 1
    $m=GUIGetMsg()
    Select
    Case $m=$GUI_EVENT_CLOSE
        _FTPClose($ftp_open)
        Exit
    EndSelect
WEnd

In the list-view, I want the icons associated with the file-types. I don't know if I made myself clear.

Bye

Share this post


Link to post
Share on other sites
maqleod

here is a link to VB6 code that will find the executable that corresponds with a file based on a shellexecute command: http://vbnet.mvps.org/index.html?code/syst...dexecutable.htm

this seems to be the important line: FindExecutable("winhlp32.hlp", "c:\winnt\system32\", sResult)

I'm sure this can be recreated in Autoit with a DLL call, I just don't know how, maybe someone else will be able to assist here.


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites
Yashied

Hi, I'm making a FTP file manager. I need help because I don't know how to show the file-type associated icon.

Try this.

#Include <WinAPI.au3>

local $Icon = _GetRegDefIcon('anyfilename.bmp')

GUICreate('Test', 200, 200)
GUICtrlCreateIcon($Icon[0], $Icon[1], 84, 84, 32, 32)
GUISetState()

do
until GUIGetMsg() = -3

func _GetRegDefIcon($Path)
    
    const $DF_NAME  = @SystemDir & '\shell32.dll'
    const $DF_INDEX = 0
    
    local $filename, $name, $ext, $count, $curver, $defaulticon, $ret[2] = [$DF_NAME, $DF_INDEX]
    
    $filename = StringTrimLeft($Path, StringInStr($Path, '\', 0, -1))
    $count = StringInStr($filename, '.', 0, -1)
    if $count > 0 then
        $count = StringLen($filename) - $count + 1
    endif
    $name = StringStripWS(StringTrimRight($filename, $count), 3)
    $ext = StringStripWS(StringRight($filename, $count - 1), 8)
    if (StringLen($name) = 0) or (StringLen($ext) = 0) then
        return $ret
    endif
    $curver = StringStripWS(RegRead('HKCR\' & RegRead('HKCR\' & '.' & $ext, '') & '\CurVer', ''), 3)
    if (@error) or (StringLen($curver) = 0) then
        $defaulticon =  _WinAPI_ExpandEnvironmentStrings(StringReplace(RegRead('HKCR\' & RegRead('HKCR\' & '.' & $ext, '') & '\DefaultIcon', ''), '''', ''))
    else
        $defaulticon =  _WinAPI_ExpandEnvironmentStrings(StringReplace(RegRead('HKCR\' & $curver & '\DefaultIcon', ''), '''', ''))
    endif
    $count = StringInStr($defaulticon, ',', 0, -1)
    if $count > 0 then
        $count = StringLen($defaulticon) - $count
        $ret[0] = StringStripWS(StringTrimRight($defaulticon, $count + 1), 3)
        if $count > 0 then
            $ret[1] = StringStripWS(StringRight($defaulticon, $count), 8)
        endif
    else
        $ret[0] = StringStripWS(StringTrimRight($defaulticon, $count), 3)
    endif
    if StringLeft($ret[0], 1) = '%' then
        $count = DllCall('shell32.dll', 'int', 'ExtractIcon', 'int', 0, 'str', $Path, 'int', -1)
        if $count[0] = 0 then
            $ret[0] = $DF_NAME
            if StringLower($ext) = 'exe' then
                $ret[1] = 2
            else
                $ret[1] = 0
            endif
        else
            $ret[0] = StringStripWS($Path, 3)
            $ret[1] = 0
        endif
    else
        if (StringLen($ret[0]) > 0) and (StringInStr($ret[0], '\', 0) = 0) then
            $ret[0] = @SystemDir & '\' & $ret[0]
        endif
    endif
    if not FileExists($ret[0]) then
        $ret[0] = $DF_NAME
        $ret[1] = $DF_INDEX
    endif
    if $ret[1] < 0 then
        $ret[1] = - $ret[1]
    else
        $ret[1] = - $ret[1] - 1
    endif
    return $ret
endfunc; _GetRegDefIcon

Share this post


Link to post
Share on other sites
Authenticity

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $STM_SETIMAGE = 0x0172
Global Const $tagSHFILEINFO =  _
    'int hIcon;' & _
    'int iIcon;' & _
    'dword dwAttributes;' & _
    'char szDisplayName[260];' & _
    'char szTypeName[80]'
; $tagSHFILEINFO

Dim $hDll = DllOpen('shell32.dll')
Dim $hGUI, $hListView, $Icon
Dim $sKey = '', $sTmp
Dim $avExtensions
Dim $i = 3
$sKey = RegEnumKey('HKCR', 2)

While 1
    $sTmp = RegEnumKey('HKCR', $i)
    If @error Or StringLeft($sTmp, 1) <> '.' Then ExitLoop
    $sKey &= '|' & $sTmp
    $i += 1
WEnd

$avExtensions = StringSplit($sKey, '|', 2)

$hGUI = GUICreate('Test', 400, 400)
$Icon = GUICtrlCreateIcon('', 0, 341, 50, 32, 32)
$hListView = _GUICtrlListView_Create($hGUI, 'File Extension', 0, 0, 250, 400)
_GUICtrlListView_SetColumnWidth($hListView, 0, 234)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_BeginUpdate($hListView)
For $i = 0 To UBound($avExtensions)-1
    _GUICtrlListView_AddItem($hListView, $avExtensions[$i], -1)
Next
_GUICtrlListView_EndUpdate($hListView)

$sKey = ''
$avExtensions = 0

GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'OnNotify')

Do
    Sleep(20)
Until GUIGetMsg() = -3

_GUICtrlListView_Destroy($hListView)
GUIDelete()
DllClose($hDll)


Func OnNotify($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $iIndex
    
    If DllStructGetData($tInfo, 'Code') = $NM_CLICK And _
        DllStructGetData($tInfo, 'hwndFrom') = $hListView Then
            $iIndex = DllStructGetData($tInfo, 'Index')
            If $iIndex > -1 Then
                _SetIcon(_GUICtrlListView_GetItemText($hListView, $iIndex))
            EndIf
    EndIf
        
    Return $GUI_RUNDEFMSG
EndFunc


Func _SetIcon($sExt)
    Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO)
    Local $pSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iSHFILEINFO = DllStructGetSize($tSHFILEINFO)
    Local $hIcon
    Local $aReturn
    
    $aReturn = DllCall($hDll, 'ulong_ptr', 'SHGetFileInfo', 'str', $sExt, 'dword', $FILE_ATTRIBUTE_NORMAL, _
        'ptr', $pSHFILEINFO, 'uint', $iSHFILEINFO, 'uint', 0x0110) ; SHGFI_ICON = 0x0100
                                                                   ; SHGFI_USEFILEATTRIBUTES = 0x0010
    
    If Not @error And $aReturn[0] Then
        $hIcon = DllStructGetData($tSHFILEINFO, 'hIcon')
        GUICtrlSendMsg($Icon, $STM_SETIMAGE, 1, $hIcon) ; IMAGE_ICON = 1
        _WinAPI_DestroyIcon($hIcon)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
Yashied

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $STM_SETIMAGE = 0x0172
Global Const $tagSHFILEINFO =  _
    'int hIcon;' & _
    'int iIcon;' & _
    'dword dwAttributes;' & _
    'char szDisplayName[260];' & _
    'char szTypeName[80]'
; $tagSHFILEINFO

Dim $hDll = DllOpen('shell32.dll')
Dim $hGUI, $hListView, $Icon
Dim $sKey = '', $sTmp
Dim $avExtensions
Dim $i = 3
$sKey = RegEnumKey('HKCR', 2)

While 1
    $sTmp = RegEnumKey('HKCR', $i)
    If @error Or StringLeft($sTmp, 1) <> '.' Then ExitLoop
    $sKey &= '|' & $sTmp
    $i += 1
WEnd

$avExtensions = StringSplit($sKey, '|', 2)

$hGUI = GUICreate('Test', 400, 400)
$Icon = GUICtrlCreateIcon('', 0, 341, 50, 32, 32)
$hListView = _GUICtrlListView_Create($hGUI, 'File Extension', 0, 0, 250, 400)
_GUICtrlListView_SetColumnWidth($hListView, 0, 234)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_BeginUpdate($hListView)
For $i = 0 To UBound($avExtensions)-1
    _GUICtrlListView_AddItem($hListView, $avExtensions[$i], -1)
Next
_GUICtrlListView_EndUpdate($hListView)

$sKey = ''
$avExtensions = 0

GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'OnNotify')

Do
    Sleep(20)
Until GUIGetMsg() = -3

_GUICtrlListView_Destroy($hListView)
GUIDelete()
DllClose($hDll)


Func OnNotify($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $iIndex
    
    If DllStructGetData($tInfo, 'Code') = $NM_CLICK And _
        DllStructGetData($tInfo, 'hwndFrom') = $hListView Then
            $iIndex = DllStructGetData($tInfo, 'Index')
            If $iIndex > -1 Then
                _SetIcon(_GUICtrlListView_GetItemText($hListView, $iIndex))
            EndIf
    EndIf
        
    Return $GUI_RUNDEFMSG
EndFunc


Func _SetIcon($sExt)
    Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO)
    Local $pSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iSHFILEINFO = DllStructGetSize($tSHFILEINFO)
    Local $hIcon
    Local $aReturn
    
    $aReturn = DllCall($hDll, 'ulong_ptr', 'SHGetFileInfo', 'str', $sExt, 'dword', $FILE_ATTRIBUTE_NORMAL, _
        'ptr', $pSHFILEINFO, 'uint', $iSHFILEINFO, 'uint', 0x0110) ; SHGFI_ICON = 0x0100
                                                                   ; SHGFI_USEFILEATTRIBUTES = 0x0010
    
    If Not @error And $aReturn[0] Then
        $hIcon = DllStructGetData($tSHFILEINFO, 'hIcon')
        GUICtrlSendMsg($Icon, $STM_SETIMAGE, 1, $hIcon) ; IMAGE_ICON = 1
        _WinAPI_DestroyIcon($hIcon)
    EndIf
EndFunc
Exelent.

:D:o:D

Share this post


Link to post
Share on other sites
Yashied
Authenticity

Read the MSDN documentation. It's the responsibility of the 'the user' the free resources. ;] Never used this function before.

Share this post


Link to post
Share on other sites
Yashied

Read the MSDN documentation. It's the responsibility of the 'the user' the free resources. ;] Never used this function before.

I use it. But you destroyed the icon, which is in control. Try to minimize and then restore the window.

:D

Share this post


Link to post
Share on other sites
Authenticity

Yes, correct ;p So I guess a little modify like if $NM_CLICK and $iIndex > -1 And $iIndex <> DllStructGetData()... may do the trick. Then you can free the resource and pick the new icon, of-course if it's not equal nothing. Heh words as code.

Edit: I think it's now quite fine, and lol .aca I'm now going to use it as my folder ico heh.

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $STM_SETIMAGE = 0x0172
Global Const $tagSHFILEINFO =  _
    'int hIcon;' & _
    'int iIcon;' & _
    'dword dwAttributes;' & _
    'char szDisplayName[260];' & _
    'char szTypeName[80]'
; $tagSHFILEINFO

Dim $hDll = DllOpen('shell32.dll')
Dim $hGUI, $hListView, $hIcon = 0, $Icon
Dim $sKey = '', $sTmp
Dim $avExtensions
Dim $i = 3
Dim $iIndex = -1
$sKey = RegEnumKey('HKCR', 2)

While 1
    $sTmp = RegEnumKey('HKCR', $i)
    If @error Or StringLeft($sTmp, 1) <> '.' Then ExitLoop
    $sKey &= '|' & $sTmp
    $i += 1
WEnd

$avExtensions = StringSplit($sKey, '|', 2)

$hGUI = GUICreate('Test', 400, 400)
$Icon = GUICtrlCreateIcon('', 0, 341, 50, 32, 32)
$hListView = _GUICtrlListView_Create($hGUI, 'File Extension', 0, 0, 250, 400)
_GUICtrlListView_SetColumnWidth($hListView, 0, 234)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_BeginUpdate($hListView)
For $i = 0 To UBound($avExtensions)-1
    _GUICtrlListView_AddItem($hListView, $avExtensions[$i], -1)
Next
_GUICtrlListView_EndUpdate($hListView)

$sKey = ''
$avExtensions = 0

GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'OnNotify')

Do
    Sleep(20)
Until GUIGetMsg() = -3

If $hIcon <> 0 Then _WinAPI_DestroyIcon($hIcon)
_GUICtrlListView_Destroy($hListView)
GUIDelete()
DllClose($hDll)


Func OnNotify($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
   
    If DllStructGetData($tInfo, 'hwndFrom') = $hListView  And _
        DllStructGetData($tInfo, 'Code') = $NM_CLICK And _
        DllStructGetData($tInfo, 'Index') <> $iIndex Then
            $iIndex = DllStructGetData($tInfo, 'Index')
            If $iIndex > -1 Then
                _SetIcon(_GUICtrlListView_GetItemText($hListView, $iIndex))
            EndIf
    EndIf
       
    Return $GUI_RUNDEFMSG
EndFunc


Func _SetIcon($sExt)
    Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO)
    Local $pSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iSHFILEINFO = DllStructGetSize($tSHFILEINFO)
    Local $aReturn
   
    $aReturn = DllCall($hDll, 'ulong_ptr', 'SHGetFileInfo', 'str', $sExt, 'dword', $FILE_ATTRIBUTE_NORMAL, _
        'ptr', $pSHFILEINFO, 'uint', $iSHFILEINFO, 'uint', 0x0110) ; SHGFI_ICON = 0x0100
                                                                   ; SHGFI_USEFILEATTRIBUTES = 0x0010
   
    If Not @error And $aReturn[0] Then
        If $hIcon <> 0 Then _WinAPI_DestroyIcon($hIcon)
        $hIcon = DllStructGetData($tSHFILEINFO, 'hIcon')
        GUICtrlSendMsg($Icon, $STM_SETIMAGE, 1, $hIcon) ; IMAGE_ICON = 1
    EndIf
EndFunc
Edited by Authenticity

Share this post


Link to post
Share on other sites
Yashied

Yes, correct ;p So I guess a little modify like if $NM_CLICK and $iIndex > -1 And $iIndex <> DllStructGetData()... may do the trick. Then you can free the resource and pick the new icon, of-course if it's not equal nothing. Heh words as code.

I would have made the following.

$hOld = GUICtrlSendMsg($Icon, $STM_SETIMAGE, 1, 0)
if $hOld <> 0 then
    _WinAPI_DestroyIcon($hOld)
endif
GUICtrlSendMsg($Icon, $STM_SETIMAGE, 1, $hIcon)

Share this post


Link to post
Share on other sites
Floppy

Thanks for replies. But how can I put that script into my script?

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
Floppy

"Give a man a fish - and you feed him for a day, teach a person how to fish - and feed him for life."

You want to get a ready-made solution. Say?

:o

Yes! :D

Share this post


Link to post
Share on other sites
ProgAndy

Hey, you could work with this: http://www.autoitscript.com/forum/index.ph...amp;hl=listview

I started to write the manager, but aborted the project since i hadn't used it


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
ProgAndy

It was the beginning of an FTP-app, but i stopped. The icon-association should work with FTP, too :D


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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  

×