Code : Tout sélectionner
;~ #include "Includes\APIConstants.au3"
#include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
;==========================================================
; Varibles
Global $iHeight = 0
Global $iTopSave = 0
Global $iEvenOdd = 0
Global $aListBtn[1][2]
Global Const $ASSOCSTR_DEFAULTICON = 15
;========================================================
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 550, 450, 273, 167, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
;~ _GUIScrollBars_Init($Form1)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
; Initialise the scroll bars
_GUIScrollBars_Init($Form1)
; Hide the horizontal one
_GUIScrollBars_ShowScrollBar($Form1, $SB_HORZ, False)
_ListFileToBtn("c:\",1, $Form1)
Func _ListFileToBtn($sFolder, $iOpt, $hGui)
Local $FileList = _FileListToArray($sFolder,"*",$iOpt)
If @error = 1 Then
GUICtrlCreateLabel("No Folder Found", 100, 200, 450, 44)
GUICtrlSetFont(-1, 32, 800, 0, "Arial")
EndIf
If @error = 4 Then
GUICtrlCreateLabel("No File Found", 100, 200, 450, 44)
GUICtrlSetFont(-1, 32, 800, 0, "Arial")
EndIf
$iHeight += Ceiling(($FileList[0]*40+50) / 16)
_GUIScrollBars_SetScrollRange($hGui, $SB_VERT, 1, $iHeight)
for $i = 1 to $FileList[0]
If $iEvenOdd Then
_AddBtn($sFolder & $FileList[$i], (($i-1) * 40) + $iTopSave, 300)
$iEvenOdd = 0
Else
_AddBtn($sFolder & $FileList[$i], ($i * 40) + $iTopSave, 40)
$iEvenOdd = 1
EndIf
Next
$iTopSave += $FileList[0] * 40
EndFunc
GUISetState(@SW_SHOW)
;~ _ArrayDisplay($aListBtn)
While 1
$Info = GUIGetCursorInfo()
$Msg = GUIGetMsg()
Switch $Msg
Case 0
ContinueLoop
Case $GUI_EVENT_CLOSE
Exit
case $aListBtn[0][0] To $aListBtn[UBound($aListBtn)-1][0]
$iTest = _ArraySearch($aListBtn,$Msg)
if @error = 0 Then
MsgBox(0,"",$aListBtn[$iTest][1])
EndIf
EndSwitch
WEnd
Func _AddBtn( $sFile, $iTop = 0, $iLeft = 0)
Local $iMaxBtn = UBound($aListBtn)
ReDim $aListBtn[$iMaxBtn + 1][2]
$aListBtn[$iMaxBtn][0] = GUICtrlCreateButton("", $iLeft, $iTop, 57, 57, $BS_ICON)
$aListBtn[$iMaxBtn][1] = $sFile
_GUICtrlSetImageEx(-1, $sFile)
GUICtrlCreateLabel(_FileGetName($sFile), $iLeft + 64, $iTop, 150, 44)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
EndFunc
;~ $sFile = "H:\autoit\Blockit\BlockIt.exe"
;~ _FileGetName($sFile)
Func _GUICtrlSetImageEx($iLV_Item, $sFile)
$sIcon = _WinAPI_AssocQueryString($sFile, $ASSOCSTR_DEFAULTICON)
$aIcon = _WinAPI_PathParseIconLocation($sIcon)
$sIconPath = _WinAPI_PathUnquoteSpaces($aIcon[0])
$iIconIndex = $aIcon[1]
If Not FileExists($sIconPath) Then
$aIcon = _FileGetIcon($sFile)
$sIconPath = $aIcon[1]
$iIconIndex = $aIcon[2]
If Not FileExists($sIconPath) Then
$sIconPath = "Shell32.dll"
$iIconIndex = 0
EndIf
EndIf
if $sIconPath = "" Then
$sIconPath = "shell32.dll"
$iIconIndex = 3
MsgBox("","",$sFile)
EndIf
GUICtrlSetImage($iLV_Item, $sIconPath, _GetIconProperIndx($iIconIndex))
EndFunc
Func _GetIconProperIndx($iIndex)
Select
Case $iIndex > 0
Return -$iIndex - 1
Case $iIndex < 0
Return -$iIndex
Case Else
Return 0
EndSelect
EndFunc
func _FileGetIcon($sFile)
Local $iOld_Opt_EES = Opt("ExpandEnvStrings", 1)
Local $sRegDefault = "", $sDefIcon = "", $sExt, $hSearch, $sIconFile, $nIcon=0
Local $aRet[3], $iError = 0
If _WinAPI_PathIsDirectory($sFile) Then
$sRegDefault = RegRead("HKCR\Folder", "")
If $sRegDefault <> "" Then $sDefIcon = RegRead("HKCR\Folder\DefaultIcon", "")
Else
$sExt = StringRegExpReplace($sFile, '^.*\.', '.')
If $sExt = ".lnk" Then
Local $aLinkInfo = FileGetShortcut($sFile)
If Not @error Then
Opt("ExpandEnvStrings", $iOld_Opt_EES)
If Not FileExists($aLinkInfo[4]) Then
Local $a_LinkInfo = _FileGetIcon($aLinkInfo[0])
If Not @error Then
$aLinkInfo[4] = $a_LinkInfo[1]
$aLinkInfo[5] = $a_LinkInfo[2]
EndIf
EndIf
Dim $aRet[3] = [2, $aLinkInfo[4], $aLinkInfo[5]]
Return $aRet
EndIf
EndIf
If $sExt = $sFile Then
$hSearch = FileFindFirstFile($sFile & ".*")
$sExt = StringRegExpReplace(FileFindNextFile($hSearch), '^.*\.', '.')
$sFile &= $sExt
FileClose($hSearch)
EndIf
$sRegDefault = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $sExt, "ProgID")
If $sRegDefault = "" Then $sRegDefault = RegRead("HKCR\" & $sExt, "")
If $sRegDefault <> "" Then $sDefIcon = RegRead("HKCR\" & $sRegDefault & "\DefaultIcon", "")
EndIf
If $sDefIcon = "" Then
$sIconFile = "shell32.dll"
ElseIf $sDefIcon <> "%1" Then
If StringRegExpReplace($sFile, "^.*\\", "") = "shell32.dll" Then
$sIconFile = $sFile
$nIcon = 0
Else
Local $aDefIconSplit = StringSplit($sDefIcon, ",")
If IsArray($aDefIconSplit) Then
$sIconFile = $aDefIconSplit[1]
If $aDefIconSplit[0] > 1 Then $nIcon = $aDefIconSplit[2]
Else
$iError = 1
EndIf
EndIf
ElseIf $sDefIcon = "%1" Then
$sIconFile = $sFile
$nIcon = 0
EndIf
Opt("ExpandEnvStrings", $iOld_Opt_EES)
Dim $aRet[3] = [2, $sIconFile, $nIcon]
Return SetError($iError, 0, $aRet)
EndFunc
Func _FileGetName($sFile)
$sFileName = StringRegExpReplace($sFile, "^.*\\", "")
$sFileName = StringRegExpReplace($sFileName, "\..*$", "")
Return $sFileName
EndFunc
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
; Get all the vertial scroll bar information
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
Case $SB_TOP ; user clicked the HOME keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM ; user clicked the END keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Max)
Case $SB_LINEUP ; user clicked the top arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINEDOWN ; user clicked the bottom arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
;~ // Set the position and then retrieve it. Due to adjustments
;~ // by Windows it may not be the same as the value set.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_VSCROLL