Jump to content

GuiCtrlSetImage


dabus
 Share

Recommended Posts

Well, my questions are the two top-todo-topics. :(

Most icons are shown correctly, but e.g. Tweakui does not seem to provide an icon. (At least irfan_view can't show any.)

Guictrlsetimage should throw an error (so I could use the default-icon for applications). But it does not. What am I missing? - There has to be some stupid fault. :lmao:

And: I'd like to skip the second search (just to see if things speed up). Why can't I copy the results from the $Search - handle to another $Var ?

Any suggestions are welcome. :P

Thx.

#cs

    

    Credit: 

    Code partly (massivly ?;) ) "stolen" from gafrost & helpfile

    

    

    ToDo:

    Check for icon-errors (folder-icons used -- damn, why ? )

    Use first search results ( $Search2=$Search does not work -- why ? )

    

    

    Add some functionality to those buttons :D

    Put all changes into one logfile

    Fix the gui-stuff

#ce



#include <GUIConstants.au3>

#include <GuiListView.au3>



Global $ListView1, $UpperDir

Global $editCtrl = "Edit1";name of the Edit control that pops up when edit a listitem....

Global $editFlag = 0, $Gui, $start, $diff, $doubleclicked, $msg





;Generated with Form Designer preview

$Gui = GUICreate("Form", 373, 368, 226, 125)

$ListView1 = GUICtrlCreateListView("Name|Type|Date|Time", 16, 80, 345, 225, $LVS_EDITLABELS)

$Label1 = GUICtrlCreateLabel("Bla.", 64, 16, 235, 49)

$Icon1 = GUICtrlCreateIcon("shell32.dll", 21, 15, 25)

$Button1 = GUICtrlCreateButton("Open", 16, 320, 49, 25)

$Button2 = GUICtrlCreateButton("Create", 80, 320, 49, 25)

$Button3 = GUICtrlCreateButton("Rename", 144, 320, 49, 25)

$Button4 = GUICtrlCreateButton("Delete", 200, 320, 57, 25)

$Button5 = GUICtrlCreateButton("Close", 272, 320, 81, 25)



$CurrentDir = "D:"



UpdateFiles()

GUISetState(@SW_SHOW)

_GUICtrlListViewSetColumnWidth ($ListView1, 0, 162)

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($ListView1) ]

$dll = DllOpen("user32.dll")



While 1

    $msg = GUIGetMsg()

    _MonitorEditState($Gui, $editCtrl, $editFlag, $ListView1, $dll, $msg, $start, $diff, $doubleclicked)

    Select

        Case $msg = $GUI_EVENT_CLOSE

            ExitLoop

        Case $msg = $GUI_EVENT_PRIMARYDOWN

            $pos = GUIGetCursorInfo()

            If ($pos[4] == $ListView1) Then

                GUICtrlSetData($Label1, "Current Index Selected: " & _GUICtrlListViewGetCurSel ($ListView1))

            EndIf

        Case $msg = $ListView1

        ; sort the list by the column header clicked on

            _GUICtrlListViewSort ($ListView1, $B_DESCENDING, GUICtrlGetState($ListView1))

        Case $msg = $Button1

            $Output = _GUICtrlListViewGetItemText ($ListView1)

            $Output = StringSplit($Output, "|")

            If $Output[2] = "" Then

                If $Output[1] = ".." Then

                    $CurrentDir = $UpperDir

                Else

                    $CurrentDir = $CurrentDir & "\" & $Output[1]

                EndIf

                UpdateFiles()

            EndIf

        Case $msg = $Button4

            $item = _GUICtrlListViewGetCurSel ($ListView1)

            $Output = _GUICtrlListViewGetItemText ($ListView1)

            $Output = StringSplit($Output, "|")

            If $Output[2] = "" Then

                $Delete = DirRemove($CurrentDir & "\" & $Output[1], 1)

            Else

                $Delete = FileDelete($CurrentDir & "\" & $Output[1] & "." & $Output[2])

            EndIf

            _GUICtrlListViewDeleteItem ($ListView1, $item)

;~              ConsoleWrite('@@ Debug(61) : $Delete = ' & $Delete & @lf & '>Error code: ' & @error & @lf);### Debug Console

;~      EndIf

    EndSelect

WEnd

DllClose($dll)

Exit



Func _MonitorEditState(ByRef $h_gui, ByRef $editCtrl, ByRef $editFlag, ByRef $ListView1, ByRef $dll, ByRef $msg, ByRef $start, ByRef $diff, ByRef $doubleclicked)

    If $msg = $GUI_EVENT_PRIMARYDOWN Then

        Local $focus = ControlGetFocus(WinGetTitle($h_gui))

        Local $pos = ControlGetPos($h_gui, "", $focus)

        Local $mpos = MouseGetPos()

        If ControlCommand($h_gui, "", $editCtrl, "IsVisible", "") Then

            If $mpos[0] < $pos[0] Or $mpos[0] > $pos[0] + $pos[2] Or _

                    $mpos[1] < $pos[1] Or $mpos[1] > $pos[1] + $pos[3] Then

                CancelEdit($ListView1)

                $editFlag = 0

            EndIf

        Else

            If (StringInStr($focus, "SysListView3")) Then

                

                $diff = TimerDiff($start)

            ; Read the current mouse-doubleclick-settings from registry

                $mousespeed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed")

                If $mousespeed = "" Then $mousespeed = 700

                If $diff < $mousespeed And $doubleclicked = 0 Then

                    $Output = _GUICtrlListViewGetItemText ($ListView1)

                    $Output = StringSplit($Output, "|")

                    If $Output[2] = "" Then

                        If $Output[1] = ".." Then

                            $CurrentDir = $UpperDir

                        Else

                            $CurrentDir = $CurrentDir & "\" & $Output[1]

                        EndIf

                        UpdateFiles()

                    Else

                        $FileType = RegRead("HKCR\." & $Output[2], "")

                        $Application = RegRead("HKCR\" & $FileType & "\shell\open\command", "")

                        Run($Application & ' "' & $CurrentDir & '\' & $Output[1] & '.' & $Output[2] & '"')

                    EndIf

                    $doubleclicked = 1

                Else

                    $doubleclicked = 0

                EndIf

                $start = TimerInit()

            EndIf

        EndIf

    EndIf

    

    Local $pressed = _IsPressedMod($dll)

    If $editFlag And $pressed = 13 Then; pressed enter

        Update($h_gui, $editCtrl, $ListView1)

    ElseIf $editFlag And $pressed = 27 Then; pressed esc

        CancelEdit($ListView1)

        $editFlag = 0

    ElseIf Not $editFlag And $pressed = 113 Then; pressed f2

        Rename($ListView1)

        $editFlag = 1

    EndIf

    Sleep(50)

    

    If ControlCommand($h_gui, "", $editCtrl, "IsVisible", "") Then

        If $editFlag = 0 Then

            $editFlag = 1

            Rename($ListView1)

        EndIf

    Else

        $editFlag = 0

    EndIf

    

EndFunc  ;==>_MonitorEditState



Func CancelEdit(ByRef $ListView1)

    GUICtrlSendMsg($ListView1, $LVM_CANCELEDITLABEL, 0, 0)

EndFunc  ;==>CancelEdit



Func _IsPressedMod($dll = "user32.dll")

    Local $aR, $bRv, $hexKey, $i

    For $i = 8 To 128

        $hexKey = '0x' & Hex($i, 2)

        $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey)

        If $aR[0] <> 0 Then Return $i

    Next

    Return 0

EndFunc  ;==>_IsPressedMod



Func Rename(ByRef $ListView1)

    Local $itemIndex = _GUICtrlListViewGetCurSel ($ListView1)

    GUICtrlSendMsg($ListView1, $LVM_EDITLABEL, $itemIndex, 0)

    HotKeySet("{Enter}", "Enter")

EndFunc  ;==>Rename



Func Enter()

; just a dummy function

EndFunc  ;==>Enter



Func Update(ByRef $h_gui, ByRef $editCtrl, ByRef $ListView1)

    Local $newText = ControlGetText($h_gui, "", $editCtrl)

    Local $item = GUICtrlRead($ListView1)

    GUICtrlSetData($item, $newText)

    HotKeySet("{Enter}")

    Send("{Enter}");quit edit mode

    $editFlag = 0

    $update = 0

EndFunc  ;==>Update



Func UpdateFiles()

    Local $Icon

    $start = TimerInit()

    ConsoleWrite('@@ Debug(188) : $CurrentDir = ' & $CurrentDir & @LF & '>Error code: ' & @error & @LF);### Debug Console

    _GUICtrlListViewDeleteAllItems ($ListView1)

; Get number of files to create the array

    $Search = FileFindFirstFile($CurrentDir & "\*.*")

    $Counter = 0

    While 1

        $SearchFile = FileFindNextFile($Search)

        If @error Then ExitLoop

        $Counter = $Counter + 1

        If $SearchFile = "." Then ContinueLoop

        If $SearchFile = ".." Then ContinueLoop

    WEnd

    FileClose($Search)

    Local $ListItems[$Counter + 2][2]

; Create first item

    GetUpperDir()

    $Time = FileGetTime($UpperDir)

    $ListItems[1][0] = '""|..|||'

    $ListItems[1][1] = "3|" & @SystemDir & "\shell32.dll|3"

; Do the search again, with output this time;)

    $Search = FileFindFirstFile($CurrentDir & "\*.*")

    $Counter = 1

    While 1

        $SearchFile = FileFindNextFile($Search)

        If @error Then ExitLoop

        $Counter = $Counter + 1

        If $SearchFile = "." Then ContinueLoop

        If $SearchFile = ".." Then ContinueLoop

        $Time = FileGetTime($CurrentDir & "\" & $SearchFile)

        $Attrib = FileGetAttrib($CurrentDir & "\" & $SearchFile)

        If StringInStr($Attrib, "D") Then

            $ListItems[$Counter][0] = '""|' & $SearchFile & "|" & "" & "|" & $Time[2] & "." & $Time[1] & "." & $Time[0] & "|" & $Time[3] & ":" & $Time[4] & ":" & $Time[5]

            $ListItems[$Counter][1] = "3|" & @SystemDir & "\shell32.dll|3"

        Else

            $a = 0

            While 1

                $a = $a + 1

                $Error = StringInStr($SearchFile, ".", 0, $a)

                If $Error = 0 Then

                    $pos = StringInStr($SearchFile, ".", 0, $a - 1)

                    $FileName = StringLeft($SearchFile, $pos - 1)

                    $Suffix = StringTrimLeft($SearchFile, $pos)

                    ExitLoop

                EndIf

            WEnd

            $ListItems[$Counter][0] = $Suffix & "|" & $FileName & "|" & $Suffix & "|" & $Time[2] & "." & $Time[1] & "." & $Time[0] & "|" & $Time[3] & ":" & $Time[4] & ":" & $Time[5]

            $FileType = RegRead("HKCR\." & $Suffix, "")

            If $FileType = "" Then

                $Icon = @SystemDir & "\shell32.dll|0"

            Else

                $Icon = RegRead("HKCR\" & $FileType & "\DefaultIcon", "")

                $Icon = StringReplace($Icon, "%SystemRoot%", @SystemDir)

                If $Icon = "%1" Then $Icon = $CurrentDir & "\" & $FileName & "." & $Suffix

                $Icon = StringReplace($Icon, ",", "|")

            EndIf

            $ListItems[$Counter][1] = StringLen($Suffix) + 1 & "|" & $Icon

        EndIf

    WEnd

    FileClose($Search)

    _ArraySort($ListItems, 0, 0, 0, 2, 0)

    For $l = 1 To UBound($ListItems) - 1

        $Output = StringSplit($ListItems[$l][1], "|")

        GUICtrlCreateListViewItem(StringTrimLeft($ListItems[$l][0], $Output[1]), $ListView1)

        If $Output[0] = 3 Then

            GUICtrlSetImage(-1, $Output[2], $Output[3])

        Else

            $Icon = GUICtrlSetImage(-1, $Output[2])

            If $Icon = 0 Then

                If StringInStr(StringLeft($ListItems[$l][0], $Output[1]), "exe") Then

                    GUICtrlSetImage(-1, @SystemDir & "\shell32.dll", 2)

                Else

                    GUICtrlSetImage(-1, @SystemDir & "\shell32.dll", 0)

                EndIf

            EndIf

        EndIf

    Next

    $diff = TimerDiff($start)

EndFunc  ;==>UpdateFiles 



Func GetUpperDir()

    $z = 0

    While 1

        $z = $z + 1

        $Error = StringInStr($CurrentDir, "\", 0, $z)

        If $Error = 0 Then

            $pos = StringInStr($CurrentDir, "\", 0, $z - 1)

            $UpperDir = StringLeft($CurrentDir, $pos - 1)

            ExitLoop

        EndIf

    WEnd

EndFunc  ;==>GetUpperDir
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...