#include <File.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIListView.au3>
#include <GUIImageList.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global Const $Path = @ScriptDir
Global $iDouble_Click_Event = False
Global $iOne_Click_Event = False
_GDIPlus_Startup()
$hForm = GUICreate('MyGUI', 800, 600, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX), $WS_EX_COMPOSITED)
Global $hListView = _GUICtrlListView_Create($hForm, 'Item', 0, 0, 800, 600, BitOR($LVS_AUTOARRANGE, $LVS_ICON))
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
_GUICtrlListView_SetTextBkColor($hListView, $CLR_NONE)
_GUICtrlListView_SetBkColor($hListView, 0xD9FFEB)
$hImageList = _GUIImageList_Create(164, 164, 5, 1)
_GUICtrlListView_SetImageList($hListView, $hImageList)
$FileList = _FileListToArray($Path, '*.jpg', 1)
If IsArray($FileList) Then
For $i = 1 To $FileList[0]
_GUICtrlListView_InsertItem($hListView, $FileList[$i], $i - 1)
If StringRegExpReplace($FileList[$i], '^.*\.', '') = 'ico' Then
_GUICtrlListView_SetItemIconEx($hListView, $i - 1, $hImageList, $Path & '\' & $FileList[$i])
Else
_GUICtrlListView_SetItemImageEx($hListView, $i - 1, $hImageList, $Path & '\' & $FileList[$i])
EndIf
Next
EndIf
GUIRegisterMsg($WM_SIZE, 'WM_SIZE')
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
If $iOne_Click_Event Then
$iOne_Click_Event = 0
$index = _GUICtrlListView_GetSelectedIndices($hListView, False)
$sText = _GUICtrlListView_GetItemText($hListView, $index)
MsgBox(0, 'Заголовок', $sText)
EndIf
If $iDouble_Click_Event Then
$iDouble_Click_Event = 0
;ToolTip('Double Click')
EndIf
WEnd
_GDIPlus_Shutdown()
Func _GUICtrlListView_SetItemIconEx($hWnd, $iIndex, ByRef $hImageList, $sFile, $iIcon = 0)
Local $Size = _GUIImageList_GetIconSize($hImageList)
If (Not $Size[0]) Or (Not $Size[1]) Then
Return 0
EndIf
Local $hIcon = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sFile, 'int', $iIcon, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
If (@error) Or (Not $hIcon[0]) Or (Not $hIcon[5]) Then
Return 0
EndIf
_GUIImageList_ReplaceIcon($hImageList, -1, $hIcon[5])
_GUICtrlListView_SetItemImage($hWnd, $iIndex, _GUIImageList_GetImageCount($hImageList) - 1)
_WinAPI_DestroyIcon($hIcon[5])
EndFunc ;==>_GUICtrlListView_SetItemIconEx
Func _GUICtrlListView_SetItemImageEx($hWnd, $iIndex, ByRef $hImageList, $sFile)
Local $Size = _GUIImageList_GetIconSize($hImageList)
If (Not $Size[0]) Or (Not $Size[1]) Then
Return 0
EndIf
Local $W, $H, $hGraphic, $hPic, $hImage, $hIcon
_GDIPlus_Startup()
$hPic = _GDIPlus_ImageLoadFromFile($sFile)
$W = _GDIPlus_ImageGetWidth($hPic)
$H = _GDIPlus_ImageGetHeight($hPic)
If ($W < 0) Or ($H < 0) Then
_GDIPlus_Shutdown()
Return 0
EndIf
If $W < $H Then
$W = $Size[0] * $W / $H
$H = $Size[1]
Else
$H = $Size[1] * $H / $W
$W = $Size[0]
EndIf
$hImage = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hPic, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage[4])
_GDIPlus_GraphicsClear($hGraphic, 0)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hPic, ($Size[0] - $W) / 2, ($Size[1] - $H) / 2, $W, $H)
$hIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'ptr', $hImage[4], 'ptr*', 0)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage[4])
_GDIPlus_ImageDispose($hPic)
_GDIPlus_Shutdown()
If Not $hIcon[2] Then
Return 0
EndIf
_GUIImageList_ReplaceIcon($hImageList, -1, $hIcon[2])
_GUICtrlListView_SetItemImage($hWnd, $iIndex, _GUIImageList_GetImageCount($hImageList) - 1)
_WinAPI_DestroyIcon($hIcon[2])
Return 1
EndFunc ;==>_GUICtrlListView_SetItemImageEx
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
Local $Pos
Switch $hWnd
Case $hForm
$Pos = WinGetClientSize($hForm)
WinMove($hListView, '', 0, 0, $Pos[0], $Pos[1])
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
$iIDFrom = DllStructGetData($tNMHDR, 'IDFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK
$iOne_Click_Event = True
Case $NM_DBLCLK
$iDouble_Click_Event = True
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc