Jump to content

Adding icons listview


Aceguy
 Share

Recommended Posts

see the section marked ;*****************************

#include<ButtonConstants.au3>
#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<GuiImageList.au3>
#include<GuiListView.au3>
#include<ListViewConstants.au3>
Opt("GUIOnEventMode", 1)

global $gui_active
Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1]
Global $Button[1][4]

$Form1 = GUICreate("Form1", 204, 422, 320, 300,-1, bitor($WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES));44 fist size then 204

$buttons = 10

Dim $Pic1[$buttons + 1]
Dim $but[$buttons + 1]
$set = 0
$last = 1
$y = 0
$gui_active = True
$size=1


For $ct = 1 To $buttons
    
    $Pic1[$ct] = GUICtrlCreateLabel("", 2, 2 + $y, 40, 40)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetResizing(-1,$GUI_DOCKALL)
    $but[$ct] = GUICtrlCreateButton("", 6, 6 + $y, 32, 32, $BS_ICON)
    GUICtrlSetOnEvent(-1, "pressed")
    GUICtrlSetResizing(-1,$GUI_DOCKALL)
    GUICtrlSetState(-1,$GUI_DROPACCEPTED)
    $y += 42
Next

$hListView = GUICtrlCreateListView("", 46, 2, 155, 418,$LVS_LIST, $WS_EX_CLIENTEDGE)
GUICtrlSetResizing(-1,$GUI_DOCKALL)
GUICtrlSetState(-1,$GUI_NODROPACCEPTED)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_SUBITEMIMAGES, $LVS_EX_FULLROWSELECT))

$hImage = _GUIImageList_Create(32,32)
_GUIImageList_AddIcon ($hImage, "shell32.dll", 0)


_GUICtrlListView_SetImageList($hListView, $hImage, 1)
_GUICtrlListView_SetView($hListView, 3)


GUICtrlSetBkColor($Pic1[1], 0x000000)


GUICtrlSetImage($but[1], "C:\Users\Ace - PC\Documents\09_FXSRESM.ico")
GUICtrlSetImage($but[2], "C:\Users\Ace - PC\Documents\1_gcdef.ico", 0)
GUICtrlSetImage($but[3], "C:\Users\Ace - PC\Documents\1_Au3InfoA.ico", 0)
GUICtrlSetImage($but[4], "C:\Users\Ace - PC\Documents\017_imageres.ico", 0)
GUICtrlSetImage($but[5], "C:\Users\Ace - PC\Documents\147_imageres.ico", 0)
GUICtrlSetImage($but[6], "C:\Users\Ace - PC\Documents\15_connect.ico", 0)
GUICtrlSetImage($but[7], "C:\Users\Ace - PC\Documents\1_mmc.ico", 0)
GUICtrlSetImage($but[8], "C:\Users\Ace - PC\Documents\1_mmci.ico", 0)
GUICtrlSetImage($but[9], "C:\Users\Ace - PC\Documents\1_mspaint.ico", 0)
GUICtrlSetImage($but[10], "C:\Users\Ace - PC\Documents\10_oobefldr.ico", 0)

GUISetOnEvent($GUI_EVENT_CLOSE, "quit")

GUISetOnEvent($GUI_EVENT_DROPPED, "Dropped", $Form1)
GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState(@SW_SHOW)

While 1
    Sleep(50)   
WEnd

Func pressed()
    Local $iD = @GUI_CtrlId
    For $x = 1 To $buttons
        If $iD = $but[$x] Then
;ConsoleWrite("BLACK    iD  -->" & $iD & "   X  --->" & $x & "   Setting   ---> " & (Int($iD / 2) - 1) & @LF)
            GUICtrlSetBkColor($Pic1[(Int($iD / 2) - 1)], 0x000000)
            $set = Int($iD / 2) - 1
        EndIf
        If $last <> $set Then GUICtrlSetBkColor($Pic1[$last], 0xffffff)
    Next

    If $gui_active = True Then
        ConsoleWrite("setting 1   ")
        If $last =$set Then
            GUICtrlSetBkColor($Pic1[$set], 0xffffff)
            $gui_active = False
            size_box()
            EndIf
    ElseIf $gui_active = False Then
        ConsoleWrite("setting 2   ")
            GUICtrlSetBkColor($Pic1[$set], 0x000000)
        $gui_active = True
        size_box()
        
    EndIf
ConsoleWrite($last&" <--last     Set   ---> "&$set&"   GUIACTIVE = "&$gui_active& @LF)
    $last=$set
EndFunc;==>pressed

Func quit()
Exit
EndFunc

Func size_box()
    $win=WinGetPos("Form1")
if $gui_active=True Then
    WinMove("Form1","",$win[0],$win[1],$win[2]+160,$win[3],0)
Else
    WinMove("Form1","",$win[0],$win[1],$win[2]-160,$win[3],0)
    EndIf
EndFunc

Func Dropped()

For $d = 0 To UBound($gaDropFiles) - 1
        ConsoleWrite(ExtFilter($gaDropFiles[$d], 1))
        $ss=StringSplit(ExtFilter($gaDropFiles[$d], 1),"\")
        $s_=$ss[0]
        $str=StringTrimRight($ss[$s_],4)
;************************************************
;************************************************
;************************************************
;     PROBLEM BELOW  <<<<<<<<<<<<<<<<<<<<<<<<       
_GUICtrlListView_AddItem($hListView,$str,ExtFilter($gaDropFiles[$d], 1))
        
    Next
EndFunc

Func ExtFilter($exPath, $exCheck = 0)
    
    If $exCheck = 0 Then
        If StringRight($exPath, 4) = ".exe" Then
            Return 1
        ElseIf StringRight($exPath, 4) = ".lnk" Then
            Dim $FGS = FileGetShortcut($exPath)
            If StringRight($FGS[0], 4) = ".exe" Then
                Return 1
            Else
                Return 0
            EndIf
        Else
            Return 0
        EndIf
    ElseIf $exCheck = 1 Then
        If StringRight($exPath, 4) = ".exe" Then
            Return $exPath
        ElseIf StringRight($exPath, 4) = ".lnk" Then
            Dim $FGS = FileGetShortcut($exPath)
            If StringRight($FGS[0], 4) = ".exe" Then Return $FGS[0]
        EndIf
    EndIf
    
EndFunc


Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
        
    Next
    
EndFunc
Edited by Aceguy
Link to comment
Share on other sites

Assuming you only want to see dropped exe and links to exe files, this works for me

#include<ButtonConstants.au3>
#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<GuiImageList.au3>
#include<GuiListView.au3>
#include<ListViewConstants.au3>
Opt("GUIOnEventMode", 1)

Global $gui_active
Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1]
Global $Button[1][4]

$Form1 = GUICreate("Form1", 204, 422, 320, 300, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES));44 fist size then 204

$buttons = 10

Dim $Pic1[$buttons + 1]
Dim $but[$buttons + 1]
$set = 0
$last = 1
$y = 0
$gui_active = True
$size = 1

For $ct = 1 To $buttons
    $Pic1[$ct] = GUICtrlCreateLabel("", 2, 2 + $y, 40, 40)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    $but[$ct] = GUICtrlCreateButton("", 6, 6 + $y, 32, 32, $BS_ICON)
    GUICtrlSetOnEvent(-1, "pressed")
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $y += 42
Next

$hListView = GUICtrlCreateListView("", 46, 2, 155, 418, $LVS_LIST, $WS_EX_CLIENTEDGE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_SUBITEMIMAGES, $LVS_EX_FULLROWSELECT))

$hImage = _GUIImageList_Create(32, 32)

_GUICtrlListView_SetImageList($hListView, $hImage, 1)
_GUICtrlListView_SetView($hListView, 3)

GUICtrlSetBkColor($Pic1[1], 0x000000)

For $i = 1 To 10
    GUICtrlSetImage($but[$i], "shell32.dll", 34 + $i)
Next

;~ GUICtrlSetImage($but[1], "C:\Users\Ace - PC\Documents\09_FXSRESM.ico")
;~ GUICtrlSetImage($but[2], "C:\Users\Ace - PC\Documents\1_gcdef.ico", 0)
;~ GUICtrlSetImage($but[3], "C:\Users\Ace - PC\Documents\1_Au3InfoA.ico", 0)
;~ GUICtrlSetImage($but[4], "C:\Users\Ace - PC\Documents\017_imageres.ico", 0)
;~ GUICtrlSetImage($but[5], "C:\Users\Ace - PC\Documents\147_imageres.ico", 0)
;~ GUICtrlSetImage($but[6], "C:\Users\Ace - PC\Documents\15_connect.ico", 0)
;~ GUICtrlSetImage($but[7], "C:\Users\Ace - PC\Documents\1_mmc.ico", 0)
;~ GUICtrlSetImage($but[8], "C:\Users\Ace - PC\Documents\1_mmci.ico", 0)
;~ GUICtrlSetImage($but[9], "C:\Users\Ace - PC\Documents\1_mspaint.ico", 0)
;~ GUICtrlSetImage($but[10], "C:\Users\Ace - PC\Documents\10_oobefldr.ico", 0)

GUISetOnEvent($GUI_EVENT_CLOSE, "quit")

GUISetOnEvent($GUI_EVENT_DROPPED, "Dropped", $Form1)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState(@SW_SHOW)

;~ $gui_active = False
;~ size_box()

While 1
    Sleep(1000)
WEnd

Func pressed()
    Local $iD = @GUI_CtrlId
    For $x = 1 To $buttons
        If $iD = $but[$x] Then
            ;ConsoleWrite("BLACK    iD  -->" & $iD & "   X  --->" & $x & "   Setting   ---> " & (Int($iD / 2) - 1) & @LF)
            GUICtrlSetBkColor($Pic1[(Int($iD / 2) - 1)], 0x000000)
            $set = Int($iD / 2) - 1
        EndIf
        If $last <> $set Then GUICtrlSetBkColor($Pic1[$last], 0xffffff)
    Next

    If $gui_active = True Then
        ConsoleWrite("setting 1   ")
        If $last = $set Then
            GUICtrlSetBkColor($Pic1[$set], 0xffffff)
            $gui_active = False
            size_box()
        EndIf
    ElseIf $gui_active = False Then
        ConsoleWrite("setting 2   ")
        GUICtrlSetBkColor($Pic1[$set], 0x000000)
        $gui_active = True
        size_box()

    EndIf
    ConsoleWrite($last & " <--last     Set   ---> " & $set & "   GUIACTIVE = " & $gui_active & @LF)
    $last = $set
EndFunc   ;==>pressed

Func quit()
    Exit
EndFunc   ;==>quit

Func size_box()
    $win = WinGetPos("Form1")
    If $gui_active = True Then
        WinMove("Form1", "", $win[0], $win[1], $win[2] + 160, $win[3], 0)
    Else
        WinMove("Form1", "", $win[0], $win[1], $win[2] - 160, $win[3], 0)
    EndIf
EndFunc   ;==>size_box

Func Dropped()
    For $d = 0 To UBound($gaDropFiles) - 1
        ConsoleWrite("ExtFilter($gaDropFiles[$d], 1)=" & ExtFilter($gaDropFiles[$d], 1) &@LF)
        $file = ExtFilter($gaDropFiles[$d], 1)
        If $file <> "" Then
            $ss = StringSplit($file, "\")
            $s_ = $ss[0]
            $str = StringTrimRight($ss[$s_], 4)
            ;ConsoleWrite("$str=" & $str & @LF)
            ;************************************************
            ;************************************************
            ;************************************************
            ;      PROBLEM BELOW  <<<<<<<<<<<<<<<<<<<<<<<<
            ;_GUICtrlListView_AddItem($hListView, $str, ExtFilter($gaDropFiles[$d], 1))
            $index = _GUIImageList_AddIcon($hImage, $file)
            _GUICtrlListView_AddItem($hListView, $str, $index)
        EndIf
    Next
EndFunc   ;==>Dropped

Func ExtFilter($exPath, $exCheck = 0)

    If $exCheck = 0 Then
        If StringRight($exPath, 4) = ".exe" Then
            Return 1
        ElseIf StringRight($exPath, 4) = ".lnk" Then
            Dim $FGS = FileGetShortcut($exPath)
            If StringRight($FGS[0], 4) = ".exe" Then
                Return 1
            Else
                Return 0
            EndIf
        Else
            Return 0
        EndIf
    ElseIf $exCheck = 1 Then
        If StringRight($exPath, 4) = ".exe" Then
            Return $exPath
        ElseIf StringRight($exPath, 4) = ".lnk" Then
            Dim $FGS = FileGetShortcut($exPath)
            If StringRight($FGS[0], 4) = ".exe" Then Return $FGS[0]
        Else
            Return ""
        EndIf
    EndIf

EndFunc   ;==>ExtFilter


Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "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

Edited by picaxe
Link to comment
Share on other sites

Your func ExtFilter only returns a filename if the dropped file is an exe or link to an exe and _GUIImageList_AddIcon can extract the icon from an exe file.

It works for me, I'm using WinXP.

Edited by picaxe
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...