cdeb Posted August 7, 2020 Posted August 7, 2020 I have different images (see attached image) loaded in an array, I want to create a listview, where I can preview them, but with the script below I only repeat the first one (see result.jpg attached). what is the mistake? Code: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIplus.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> Local $aJpgList = get_list_jpg() Example($aJpgList) Func get_list_jpg() ; List all the files and folders in the desktop directory using the default parameters. Local $aFileList = _FileListToArray(@ScriptDir, "*.jpg", $FLTA_FILES) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf ; Display the results returned by _FileListToArray. ;_ArrayDisplay($aFileList, "$aFileList") Return($aFileList) EndFunc Func Example($aJpgList) _GDIPlus_Startup() Local $idListview, $hImage GUICreate("JpegList", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create(64, 64) _GUICtrlListView_AddColumn($idListview, "Image", 180) _GUICtrlListView_SetImageList($idListview, $hImage, 1) Global $GDIpBmpLarge Global $GDIpBmpResized Global $GDIbmp For $r = 1 To UBound($aJpgList)-1 local $sFileName = @ScriptDir&"\"&$aJpgList[$r] ConsoleWrite('$sFileName:' & @TAB& $sFileName & @CRLF) $GDIpBmpLarge = _GDIPlus_BitmapCreateFromFile($sFileName) ;GDI+ image! $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image! _GUIImageList_Add($hImage, $GDIbmp) ; Add items _GUICtrlListView_AddItem($idListview, $aJpgList[$r], 0) Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup resources _GDIPlus_BitmapDispose($GDIpBmpLarge) _GDIPlus_BitmapDispose($GDIpBmpResized) _WinAPI_DeleteObject($GDIbmp) _GDIPlus_Shutdown() GUIDelete() EndFunc ;==>Example
Dan_555 Posted August 7, 2020 Posted August 7, 2020 (edited) The item's image in your code is always pointing at the first image, change it like this: _GUICtrlListView_AddItem($idListview, $aJpgList[$r], $r-1) and maybe add/move this _WinAPI_DeleteObject($GDIbmp) _GDIPlus_BitmapDispose($GDIpBmpResized) _GDIPlus_BitmapDispose($GDIpBmpLarge) in to the same loop (just before next). Edited August 7, 2020 by Dan_555 Some of my script sourcecode
cdeb Posted August 7, 2020 Author Posted August 7, 2020 perfect works. Thank you here is the correct code: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIplus.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> Local $aJpgList = get_list_jpg() Example($aJpgList) Func get_list_jpg() ; List all the files and folders in the desktop directory using the default parameters. Local $aFileList = _FileListToArray(@ScriptDir, "*.jpg", $FLTA_FILES) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf ; Display the results returned by _FileListToArray. ;_ArrayDisplay($aFileList, "$aFileList") Return($aFileList) EndFunc Func Example($aJpgList) _GDIPlus_Startup() Local $idListview, $hImage GUICreate("JpegList", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create(64, 64) _GUICtrlListView_AddColumn($idListview, "Image", 180) _GUICtrlListView_SetImageList($idListview, $hImage, 1) Global $GDIpBmpLarge Global $GDIpBmpResized Global $GDIbmp For $r = 1 To UBound($aJpgList)-1 local $sFileName = @ScriptDir&"\"&$aJpgList[$r] ConsoleWrite('$sFileName:' & @TAB& $sFileName & @CRLF) $GDIpBmpLarge = _GDIPlus_BitmapCreateFromFile($sFileName) ;GDI+ image! $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 64,64) ;GDI+ image $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image! _GUIImageList_Add($hImage, $GDIbmp) ; Add items _GUICtrlListView_AddItem($idListview, $aJpgList[$r], $r-1) ;cleanup resources _GDIPlus_BitmapDispose($GDIpBmpLarge) _GDIPlus_BitmapDispose($GDIpBmpResized) _WinAPI_DeleteObject($GDIbmp) Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_Shutdown() GUIDelete() EndFunc ;==>Example
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now