Jump to content
Wonvy

List view display thumbnails

Recommended Posts

Wonvy

I think in the listview display pictures like Windows resource manager like that

English is not useful software translation, don't mind,I myself find examples are ICONS list

Which experienced, give an example, thank you

post-64381-0-06080100-1303559724_thumb.j

post-64381-0-41049900-1303559843_thumb.j

On the right side of the rectangular frame to put pictures within thumbnails

Share this post


Link to post
Share on other sites
Jayson

This might help you out on your projet :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <EditConstants.au3>
#Include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

Global $sExtFilter = "bmp|gif|jpeg|jpg|png|tif|tiff"
Global $hGui, $Path, $BRowse, $LV, $Pic, $Msg
Global $hImageList, $sCur, $sLast, $iDX, $iPicState = 0, $DoubleClick = -1

$hGui = GUICreate("Image Viewer", 490, 620)
$Path = GUICtrlCreateInput("", 10, 10, 400, 20, $ES_READONLY)
$BRowse = GUICtrlCreateButton("Browse", 420, 10, 60, 20)
$LV = GUICtrlCreateListView("",  5, 40, 480, 575, -1, BitOr($WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetView($LV, 1)
_GUICtrlListView_SetIconSpacing($LV, 75, 60)
$Pic = GUICtrlCreatePic("", 200, 80, 440, 440)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browse
            _Browse()
    EndSwitch
WEnd

Func _Browse()
    Local $FSF, $FL2A, $hBmp, $iCnt = 0
    $FSF = FileSelectFolder("Browse for folder containing pictures", "", "", $hGui)
    If Not @error And FileExists($FSF) Then
        If StringRight($FSF, 1) <> "\" Then $FSF &= "\"
        $FL2A = _FileListToArray($FSF, "*", 1)
        If Not @Error Then
            If IsPtr($hImageList) Then
                _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV))
                _GUiImageList_Destroy($hImageList)
                $hImageList = ""
                _hBmpToPicControl($Pic, $hBmp)
                GUICtrlSetImage($Pic, "")
                $iDX = -1
                $iPicState = 0
                $sCur = ""
                $sLast = ""
            EndIf
            $hImageList = _GUiImageList_Create(60, 60, 5, 3)
            _GUICtrlListView_SetImageList($LV, $hImageList, 0)
            For $i = 1 To $FL2A[0]
                If StringRegExp($FL2A[$i], "(?i)\.(" & $sExtFilter & ")", 0) Then
                    $hBmp = _GetImage($FSF & $FL2A[$i], 60)
                    _GUiImageList_Add($hImageList, $hBmp)
                    _WinAPI_DeleteObject($hBmp)
                    _GUICtrlListView_AddItem($LV, $FL2A[$i], $iCnt)
                    _GUICtrlListView_SetItemImage($LV, $iCnt, $iCnt)
                    $iCnt += 1
                EndIf
            Next
            GUICtrlSetData($Path, $FSF)
        EndIf
        WinSetTitle($hGui, "", "Images Found: " & $iCnt)
    EndIf
EndFunc

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2
    _GDIPlus_Startup()
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    $aGS = _GetScale($iW, $iH, $iWH)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Return $hBmp2
EndFunc

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH/($iW/$iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW/($iH/$iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aIDX
    $hWndListView = GUICtrlGetHandle($LV)
    $tNMHDR = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code', $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    $iDX = _GUICtrlListView_GetNextItem($hWndListView)
                Case $NM_DBLCLK
                    $DoubleClick = _GUICtrlListView_GetNextItem($hWndListView)
                Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code;int_ptr VKey;int Flags', $ilParam)
                    Switch BitAnd(DllStructGetData($tInfo, "VKey"), 0xFFFF)
                        Case $VK_UP
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) -1
                            If $iDX < 0 Then $iDX = 0
                        Case $VK_DOWN
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) + 1
                            If $iDX >= _GUICtrlListView_GetItemCount($hWndListView) Then $iDX -= 1
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Edited by Jayson

Share this post


Link to post
Share on other sites
guinness

Nice Example Jayson!


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
qwert

Both useful and instructive. Thanks. Too bad it's not under Examples, where people could locate it more easily.

Share this post


Link to post
Share on other sites
Wonvy

Thank you, could not speak English

Share this post


Link to post
Share on other sites
nassausky
On 4/26/2011 at 9:33 AM, Jayson said:

This might help you out on your project :

 

Really appreciate this demo but it runs and shows it found 2 images in a particular folder but nothing else. The main GUI is blank. Has anything changed in autoit since this was posted that might keep it from displaying the images in the folder?

On 4/26/2011 at 9:33 AM, Jayson said:

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <EditConstants.au3>
#Include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

Global $sExtFilter = "bmp|gif|jpeg|jpg|png|tif|tiff"
Global $hGui, $Path, $BRowse, $LV, $Pic, $Msg
Global $hImageList, $sCur, $sLast, $iDX, $iPicState = 0, $DoubleClick = -1

$hGui = GUICreate("Image Viewer", 490, 620)
$Path = GUICtrlCreateInput("", 10, 10, 400, 20, $ES_READONLY)
$BRowse = GUICtrlCreateButton("Browse", 420, 10, 60, 20)
$LV = GUICtrlCreateListView("",  5, 40, 480, 575, -1, BitOr($WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetView($LV, 1)
_GUICtrlListView_SetIconSpacing($LV, 75, 60)
$Pic = GUICtrlCreatePic("", 200, 80, 440, 440)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browse
            _Browse()
    EndSwitch
WEnd

Func _Browse()
    Local $FSF, $FL2A, $hBmp, $iCnt = 0
    $FSF = FileSelectFolder("Browse for folder containing pictures", "", "", $hGui)
    If Not @error And FileExists($FSF) Then
        If StringRight($FSF, 1) <> "\" Then $FSF &= "\"
        $FL2A = _FileListToArray($FSF, "*", 1)
        If Not @Error Then
            If IsPtr($hImageList) Then
                _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV))
                _GUiImageList_Destroy($hImageList)
                $hImageList = ""
                _hBmpToPicControl($Pic, $hBmp)
                GUICtrlSetImage($Pic, "")
                $iDX = -1
                $iPicState = 0
                $sCur = ""
                $sLast = ""
            EndIf
            $hImageList = _GUiImageList_Create(60, 60, 5, 3)
            _GUICtrlListView_SetImageList($LV, $hImageList, 0)
            For $i = 1 To $FL2A[0]
                If StringRegExp($FL2A[$i], "(?i)\.(" & $sExtFilter & ")", 0) Then
                    $hBmp = _GetImage($FSF & $FL2A[$i], 60)
                    _GUiImageList_Add($hImageList, $hBmp)
                    _WinAPI_DeleteObject($hBmp)
                    _GUICtrlListView_AddItem($LV, $FL2A[$i], $iCnt)
                    _GUICtrlListView_SetItemImage($LV, $iCnt, $iCnt)
                    $iCnt += 1
                EndIf
            Next
            GUICtrlSetData($Path, $FSF)
        EndIf
        WinSetTitle($hGui, "", "Images Found: " & $iCnt)
    EndIf
EndFunc

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2
    _GDIPlus_Startup()
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    $aGS = _GetScale($iW, $iH, $iWH)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Return $hBmp2
EndFunc

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH/($iW/$iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW/($iH/$iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aIDX
    $hWndListView = GUICtrlGetHandle($LV)
    $tNMHDR = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code', $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    $iDX = _GUICtrlListView_GetNextItem($hWndListView)
                Case $NM_DBLCLK
                    $DoubleClick = _GUICtrlListView_GetNextItem($hWndListView)
                Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code;int_ptr VKey;int Flags', $ilParam)
                    Switch BitAnd(DllStructGetData($tInfo, "VKey"), 0xFFFF)
                        Case $VK_UP
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) -1
                            If $iDX < 0 Then $iDX = 0
                        Case $VK_DOWN
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) + 1
                            If $iDX >= _GUICtrlListView_GetItemCount($hWndListView) Then $iDX -= 1
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

 

Share this post


Link to post
Share on other sites
spudw2k
On 7/10/2018 at 9:05 AM, nassausky said:

Has anything changed in autoit since this was posted

Well, considering the example post was made over 7 years ago, I'd wager yes. ;) 

Looking at the Release History, the most recent version that the example could have been written in was version 3.3.6.1.  So if you feel like doing detective work to see if a documented in the Script Breaking Change log is the cause, start with v3.3.8.0 and work your way up.  If you don't find anything, start scrubbing through the script and check the returns from the function calls to find where the error(s) happen(s).

Share this post


Link to post
Share on other sites
nassausky

Nice to hear your idea. Never knew they had a cool log called "Script Breaking Change Log" haha.

 

Thanks again @spudw2k

Share this post


Link to post
Share on other sites
nassausky

You're a genius @spudw2k

 

Turns out it was a simple change from 1 to 0 in line 21:

_GUICtrlListView_SetView($LV, 1) ; Changing the last parameter from 1 to 0 did the magic

 

There was a script breaking change in 3.3.12.0

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×