Iczer Posted October 14, 2020 Share Posted October 14, 2020 I wanted to adapt this example to virtual ListView where thumbnails would be stored in db, but i do not know method to dynamically replace ImageList in ListView and also - is it even good idea to have huge ImageList? It's size would be (5...8) x Rows in virtual ListView. Is it possible to {dinamically?} set images as binaries to ListView cells without use ImageList? 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> Global $iGUIWidth, $iGUIHeidth, $iGUILeft, $iGUIRight Global $iEntryWidth, $iEntryHeidth Global $aJpgList 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 = _FileListToArrayRec (@ScriptDir & "\Pic\", "*.jpg", $FLTA_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH) 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 $iGUIWidth = 988 $iGUIHeidth = 1210 $iGUILeft = -1 $iGUIRight = -1 $iEntryWidth = 198 $iEntryHeidth = 288 $iPicWidth = 190 $iPicHeidth = 285 $iColumnCount = Round($iGUIWidth/$iEntryWidth) $iGUIWidth = $iColumnCount * $iEntryWidth + 16 + 14 GUICreate("JpegList", $iGUIWidth, $iGUIHeidth, -1, -1, $WS_OVERLAPPEDWINDOW) $idListview = GUICtrlCreateListView("", 2, 2, $iGUIWidth - 4, $iGUIHeidth - 32, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP, $LVS_EX_SUBITEMIMAGES)) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create($iPicWidth, $iPicHeidth) For $i = 1 To $iColumnCount _GUICtrlListView_AddColumn($idListview, "Image", $iEntryWidth) Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) Global $GDIpBmpLarge Global $GDIpBmpResized = 0 Global $GDIbmp $iIndex = 0 $iSubItem = 0 $iPic_RatioMax = $iPicWidth/$iPicHeidth For $r = 1 To UBound($aJpgList)-1 local $sFileName = @ScriptDir&"\Pic\"&$aJpgList[$r] $GDIpBmpLarge = _GDIPlus_BitmapCreateFromFile($sFileName) ;GDI+ image! $aDim = _GDIPlus_ImageGetDimension($GDIpBmpLarge) if $aDim[0] <> $iPicWidth Or $aDim[1] > $iPicHeidth Then $iPic_Ratio = $aDim[0]/$aDim[1] Select Case $iPic_Ratio > $iPic_RatioMax $iPic_WNew = $iPicWidth $iPic_HNew = Round($iPicWidth/$iPic_Ratio,0) Case $iPic_Ratio < $iPic_RatioMax $iPic_WNew = Round($iPicHeidth*$iPic_Ratio,0) $iPic_HNew = $iPicHeidth Case $iPic_Ratio = $iPic_RatioMax $iPic_WNew = $iPicWidth $iPic_HNew = $iPicHeidth EndSelect $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 190,$iPic_HNew) ;GDI+ image $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image! $imgInd = _GUIImageList_Add($hImage, $GDIbmp) Else $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpLarge) ;GDI image! $imgInd = _GUIImageList_Add($hImage, $GDIbmp) endif If $iSubItem = 0 Then _GUICtrlListView_AddItem($idListview, $aJpgList[$r], $imgInd) Else _GUICtrlListView_AddSubItem($idListview, $iIndex, $aJpgList[$r], $iSubItem, $imgInd) EndIf $iSubItem += 1 If $iSubItem > ($iColumnCount-1) Then $iIndex += 1 $iSubItem = 0 EndIf ;cleanup resources _GDIPlus_BitmapDispose($GDIpBmpLarge) If $GDIpBmpResized <> 0 Then _GDIPlus_BitmapDispose($GDIpBmpResized) $GDIpBmpResized = 0 EndIf _WinAPI_DeleteObject($GDIbmp) Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_Shutdown() GUIDelete() EndFunc ;==>Example Link to comment Share on other sites More sharing options...
LarsJ Posted October 14, 2020 Share Posted October 14, 2020 Yes, You can custom or owner draw the images directly with GDI/GDI+ functions without relying on an imagelist. A Virtual listview immediately supports the custom draw technique. To set the height of the rows in the listview to match the height of the images, you can probably add an imagelist with a single image of the correct height. To use the owner draw method, you can combine the virtual ($LVS_OWNERDATA) and owner draw ($LVS_OWNERDRAWFIXED) styles. By replying to WM_MEASUREITEM messages it's easy to set the height of the listview rows. Search forums for the topics and it should be possible to find code examples. Zedna 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Iczer Posted October 15, 2020 Author Share Posted October 15, 2020 Thanks! Link to comment Share on other sites More sharing options...
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