Jump to content

listview icons


Recommended Posts

I'm trying to emulate the desktop, and have run into a few road blocks. Right now I'm working on Icon transparency. I made up this little script to start off testing with. I made every icon the empty recycle bin icon. What I'd like to do is have the names listed under the icons. And if anyone can figure out how to get the icon locations for me that'd be great too. I haven't done as much research on that part. maybe able to find something on my own on that one.

CODE
#Include <GuiListView.au3>

#include <Array.au3>

#Include <Misc.au3>

#Include <GuiImageList.au3>

HotKeySet("{ESC}","close")

$hProgMan = WinGetHandle("Program Manager")

$progmanpos = WinGetPos($hProgman)

$hDeskTop = ControlGetHandle( "Program Manager", "", "SysListView321" )

$desktoppos = ControlGetPos($hprogman,"",$hdesktop)

Global $oldcount = _GUICtrlListView_GetItemCount($hdesktop)

Global $aIcons[_GUICtrlListView_GetItemCount($hDeskTop)][4]

Global $bIcons[_GUICtrlListView_GetItemCount($hDeskTop)][4]

Global $dll = DllOpen("user32.dll")

$images=_GUIImageList_Create(32,32,5,3)

For $i = 0 to _GUICtrlListView_GetItemCount($hDeskTop) - 1

; Name

$bIcons[$i][0] = _GUICtrlListView_GetItemText($hDeskTop, $i)

$bPos = _GUICtrlListView_GetItemPosition($hDeskTop, $i)

; Left

$bIcons[$i][1] = $bPos[0]

; Top

$bIcons[$i][2] = $bPos[1]

$bIcons[$i][3] = _GUICtrlListView_GetItemImage($hDesktop,$i)

_GUIImageList_AddIcon($images,@SystemDir & "\shell32.dll",32,True)

$bIcons[0][0] = $i

Next

$fuxdesktop = GUICreate("Fux Desktop",$progmanpos[2] - $progmanpos[0], $progmanpos[3] - $progmanpos[1], $progmanpos[0] + 80, $progmanpos[1])

$desktop2 = GUICtrlCreateListView("", $desktoppos[0] , $desktoppos[1],$desktoppos[2] - $desktoppos[0] ,$desktoppos[3] - $desktoppos[1])

_GUICtrlListView_SetImageList($desktop2,$images,1)

_GUICtrlListView_SetExtendedListViewStyle($desktop2,$LVS_SHOWSELALWAYS)

_GUICtrlListView_AddColumn($desktop2, " ", 220)

GUISetState()

For $i = 0 to $bIcons[0][0]

_GUICtrlListView_AddItem($desktop2,$bIcons[$i][0],0)

_GUICtrlListView_SetItemImage($fuxdesktop,$i,$bIcons[$i][3],1)

Next

While 1

Sleep(10)

WEnd

Func close()

Exit

EndFunc

Giggity

Link to comment
Share on other sites

As for the first, I've got that functionality. I grab the current positions and all. As far as the second, I'll have too look into it deeper to see if it pulls the actual icons or if it has it's own library. But it doesn't appear either addresses putting the icon above the text.

Edit: thanks for those links btw. Can someone grab the code and forward that my way? I always get that the download is blocked for some reason.

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

hi,

don't know if it'll help, but here's some scrapped code I wrote last year..

#Include <GuiConstantsEx.au3>
#Include <WindowsConstants.au3>
#include <Constants.au3>
#Include <GuiListView.au3>
#Include <GuiImageList.au3>
#include <WinAPI.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)

Global $apw = @DesktopWidth, $aph = @DesktopHeight, $GIP
Global $DeskBkClr = 0x000000, $TextClr = 0xffffff
Global $GetIconOrg = GetIconPos(), $Desktop, $hImage, $aDrag[3], $DragState
$aDrag[0] = -1

$Gui = GuiCreate("", $apw, $aph, 0, 0, $WS_POPUP);, $WS_EX_TOPMOST
GuiSetBkColor($DeskBkClr, $Gui)
GUISetOnEvent($GUI_EVENT_CLOSE, "Event", $Gui)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "Event", $Gui)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Event", $Gui)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "Event", $Gui)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "Event", $Gui)

$Desktop = _GUICtrlListView_Create ($Gui, "", 0, 0, $apw, $aph, BitOR($LVS_ICON,$LVS_SINGLESEL,$LVS_NOSCROLL))
_GUICtrlListView_SetExtendedListViewStyle ($Desktop, $LVS_EX_FULLROWSELECT + $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetBkColor($Desktop, $DeskBkClr)
_GUICtrlListView_SetTextColor($Desktop, $TextClr)
_GUICtrlListView_SetTextBkColor($Desktop, $CLR_NONE)

$hImage = _GUIImageList_Create (32, 32, 5, 3)
_AddIcon($hImage, @SystemDir & "\shell32.dll", 15);My Computer 0
_AddIcon($hImage, @SystemDir & "\shell32.dll", 17);My Network Places 1
_AddIcon($hImage, @SystemDir & "\shell32.dll", 31);Recycle Empty 2
_AddIcon($hImage, @SystemDir & "\shell32.dll", 126);My Docs 3
_AddIcon($hImage, @SystemDir & "\shell32.dll", 32);Recycle Full 4
_GUICtrlListView_SetImageList ($Desktop, $hImage, 0)
LoadSCOrg()

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Sleep(10)
WEnd

Func Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            If $aDrag[0] <> -1  Then
                $DragState = 1
                _GUICtrlListView_DrawDragImage($Desktop, $aDrag)
            EndIf
        Case $GUI_EVENT_MOUSEMOVE
            If $DragState Then _GUICtrlListView_DrawDragImage($Desktop, $aDrag)
        Case $GUI_EVENT_PRIMARYUP
            If $DragState Then
                $DragState = 0
                Local $MGP = MouseGetPos()
                If $MGP[0] > ($apw - 54) Then $MGP[0] = ($apw - 54)
                If $MGP[1] > ($aph -80) Then $MGP[1] = ($aph -80)               
                _GUICtrlListView_BeginUpdate($Desktop)
                _GUICtrlListView_SetItemPosition32($Desktop, _GUICtrlListView_GetNextItem($Desktop) , $MGP[0], $MGP[1])
                _GUICtrlListView_EndUpdate($Desktop)
                $aDrag[0] = -1
            EndIf
    EndSwitch
EndFunc

Func LoadSCOrg()
    Local $SPIN = StringSplit("My Computer|My Network Places|Recycle Bin|My Documents", "|")
    _GUICtrlListView_BeginUpdate($Desktop)
    For $i = 1 To $SPIN[0]
        For $j = 1 To $GetIconOrg[0][0]
            If $GetIconOrg[$j][0] = $SPIN[$i] Then 
                _GUICtrlListView_AddItem($Desktop, $GetIconOrg[$j][0], $i - 1)
                Local $FT = _GUICtrlListView_FindText($Desktop, $GetIconOrg[$j][0], -1, FALSE)
                _GUICtrlListView_SetItemPosition32($Desktop, $FT, $GetIconOrg[$j][1], $GetIconOrg[$j][2])   
  
            EndIf
        Next
    Next
    For $j = 1 To $GetIconOrg[0][0]    
        If $GetIconOrg[$j][3] <> "" Then
                Local $FGS = FileGetShortcut($GetIconOrg[$j][3])
                If Not @error Then
                    ConsoleWrite($FGS[0] & @LF)
                    If StringRight($FGS[0], 4) = ".exe" Or StringRight($FGS[0], 4) = ".dll" Then
                    _AddIcon($hImage, $FGS[0], 0)
                    _GUICtrlListView_AddItem($Desktop, $GetIconOrg[$j][0], _GUIImageList_GetImageCount($hImage) - 1)
                    Local $FT = _GUICtrlListView_FindText($Desktop, $GetIconOrg[$j][0], -1, FALSE)
                   _GUICtrlListView_SetItemPosition32($Desktop, $FT, $GetIconOrg[$j][1], $GetIconOrg[$j][2])
                   EndIf
               EndIf
           EndIf
    Next       
    _GUICtrlListView_EndUpdate($Desktop)
EndFunc 

Func _AddIcon($hWnd, $sFile, $iIndex = 0)
    Local $pIcon, $tIcon, $iResult, $hIcon
    $tIcon = DllStructCreate("int Icon")
    $pIcon = DllStructGetPtr($tIcon)
    $iResult = _WinAPI_ExtractIconEx ($sFile, $iIndex, $pIcon, 0, 1)
    $hIcon = DllStructGetData($tIcon, "Icon")
    $iResult = _GUIImageList_ReplaceIcon ($hWnd, -1, $hIcon)
    _WinAPI_DestroyIcon($hIcon)
EndFunc

Func GetIconPos()
    Local $hWnd = ControlGetHandle("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]")
    If @error Then Return 0
    Dim $GIP[_GUICtrlListView_GetItemCount($hWnd)+1][6]
    If Not IsArray($GIP) Then Return 0 
    $GIP[0][0] = UBound($GIP) -1
    For $i = 1 To $GIP[0][0]
        $GIP[$i][0] = _GUICtrlListView_GetItemText($hWnd, $i -1)
        $GIP[$i][1] = _GUICtrlListView_GetItemPositionX($hWnd, $i -1)
        $GIP[$i][2] = _GUICtrlListView_GetItemPositionY($hWnd, $i -1)
    Next
    ShortCutCompare(@DesktopDir, $GIP)
    ShortCutCompare(@DesktopCommonDir, $GIP)
    Return $GIP
EndFunc

Func ShortCutCompare($iPath, ByRef $aComp)
    Local $FL2A = _FileListToArray($iPath, "*")
    If Not @error Then
        For $i = 1 To $FL2A[0]
            For $j = 1 To $GIP[0][0]
                If $aComp[$j][0] = StringTrimRight($FL2A[$i], 4) Or $GIP[$j][0] = $FL2A[$i] Then
                    $aComp[$j][3] = $iPath & "\" & $FL2A[$i]
                EndIf
            Next
        Next
    EndIf
EndFunc
    
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $Desktop
    If Not IsHWnd($Desktop) Then $hWndListView = GUICtrlGetHandle($Desktop)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_BEGINDRAG
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    $aDrag = _GUICtrlListView_CreateDragImage ($Desktop, DllStructGetData($tInfo, "Item"))
                                $aDrag[1] = ($aDrag[1]-16)
                    $aDrag[2] = ($aDrag[2]-16)
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
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...