#include <Array.au3>
#include <GDIPlus.au3>
#include <GuiButton.au3>
#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <File.au3>
#include <WindowsConstants.au3>
#include "_GUIImageList_AddBitmapEx.au3"

Dim $aCount[1], $aExt[5] = ["*.jpg", "*.png", "*.bmp", "*.ico", "*.gif"]
$image_path = FileSelectFolder("Select folder with images", "")
For $i = 0 To UBound($aExt) - 1
	$aTmp = _FileListToArray($image_path, $aExt[$i] , 1)
	_ArrayConcatenate($aCount, $aTmp, 1)
Next
$aCount[0] = UBound($aCount)

If Not IsArray($aCount) Then Exit MsgBox(16, "Error", "No images found in " & $image_path, 10)

$iX = 800
$iY = 600
$hGUI = GUICreate("Image to _GUIImageList Example by UEZ 2010", $iX, $iY)
$hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 20, 20, 70, 335, $CBS_DROPDOWNLIST)

Dim $bitmap_from_file[$aCount[0]]
_GDIPlus_Startup()

$iCX = 48
$iCY = 48
$hImage = _GUIImageList_Create($iCX, $iCY, 5)
For $i = 1 To $aCount[0] - 1
	_GUIImageList_AddBitmapEx($hImage, $image_path & "\"  & $aCount[$i], $iCX, $iCY)
Next

_GUICtrlComboBoxEx_BeginUpdate ($hCombo)
_GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)
For $i = 0 To $aCount[0] - 2
    _GUICtrlComboBoxEx_AddString($hCombo, $image_path & "\"  & $aCount[$i + 1], $i + 1, $i + 1)
Next
_GUICtrlComboBoxEx_EndUpdate ($hCombo)

_GUICtrlComboBoxEx_SetItemHeight($hCombo, 0, $iCY)
_GUICtrlComboBoxEx_SetCurSel($hCombo, 0)
$botton = GUICtrlCreateButton("Display Image", 120, 20, 90, 55, $BS_BITMAP)

GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)


$iW = 256
$iH = 256
GUICtrlCreateIcon("", 0, ($iX - $iW) * 0.5, ($iY - $iH) * 0.5)
$Icon = GUICtrlGetHandle(-1)

While 1
    $msg = GUIGetMsg()
    Select
		Case $msg = $gui_event_close
			_GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
			GUIDelete($hGUI)
			Exit
        Case $msg = $botton
			_WinAPI_RedrawWindow($hGUI)
			$select = _GUICtrlComboBoxEx_GetCurSel($hCombo) + 1
			$aItem = _GUICtrlComboBoxEx_GetItem($hCombo, $select)
			WinSetTitle($hGUI, "", $aItem[0])
			$suffix = StringRight($aItem[0], 3)
			If $suffix = "ico" Then
				$iW = 256
				$iH = 256
				$aRet = DllCall('comctl32.dll ', 'uint', 'LoadIconWithScaleDown', 'ptr', 0, 'wstr', $aItem[0], 'int', $iW, 'int', $iH, 'ptr*', 0)
				$hIcon = $aRet[5]
				$hPrev = _SendMessage($Icon, 0x0172, 1, $hIcon) ;$STM_SETIMAGE = 0x0172
				If $hPrev Then
					DllCall('user32.dll', 'int', 'DestroyIcon', 'ptr', $hPrev)
				EndIf
				_WinAPI_DestroyIcon($hIcon)
			Else
				$hImg = _GDIPlus_BitmapCreateFromFile($aItem[0])
				$iW = _GDIPlus_ImageGetWidth($hImg)
				$iH = _GDIPlus_ImageGetHeight($hImg)
				If $iW < $iX * 0.8 And $iH < $iY - 100 Then
					_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImg, ($iX - $iW) * 0.5, ($iY - $iH) * 0.5, $iW, $iH)
				Else
					$iW = ($iX / $iW) * $iW * 0.8
					$iH = ($iY / $iH) * $iH * 0.8
					_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImg, ($iX - $iW) * 0.5, 100, $iW, $iH)
				EndIf
				_GDIPlus_BitmapDispose($hImg)
			EndIf
    EndSelect
WEnd