Sign in to follow this  
Followers 0
zackrspv

List View Image List from File

2 posts in this topic

So, i'd like to do something like this:

Posted Image

And found a similiar coding on the forum here, but can't seem to get it to work. It can display images in $LVS_ICON mode, but not $LVS_REPORT mode, what am i missing?

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>

Global $files[1] = [0]

_GDIPlus_Startup()

Local $LV, $hImage
Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
$hGUI = GUICreate("thumbnails", 585, 350)

$LV = GUICtrlCreateListView("Pics", 2, 2, 394, 268)
GUICtrlSetStyle(-1, $LVS_REPORT)
GUISetState()

GUISetCursor(15, 1)

$search = FileFindFirstFile("*.jpg")
If $search <> -1 Then
    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        $files[0] += 1
        _ArrayAdd($files, @ScriptDir & "\" & $file)
    WEnd
EndIf

; create image list
$hiList = _GUIImageList_Create(42, 42)

; create parent graphic object
$hWnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hWnd)
$hGraphics1 = _GDIPlus_GraphicsCreateFromHDC($hDC)
_WinAPI_ReleaseDC($hWnd, $hDC)

For $i = 1 To $files[0]
    ; create resized graphic to place the image into
    $hBmp = _GDIPlus_BitmapCreateFromGraphics(42, 42, $hGraphics1)
    $hGraphics2 = _GDIPlus_ImageGetGraphicsContext($hBmp)

    ; load image
    $hImage = _GDIPlus_ImageLoadFromFile($files[$i])
    $iRatio = _GDIPlus_ImageGetWidth($hImage) / _GDIPlus_ImageGetHeight($hImage)
    $h = 42 / $iRatio
    If $h > 42 Then
        $h = 42
        $y = 0
        $w = 42 * $iRatio
        $x = (42 - $w) / 2
    Else
        $x = 0
        $w = 42
        $y = (42 - $h) / 2
    EndIf
    ; draw the resized image and get handle to HBITMAP
    _GDIPlus_GraphicsDrawImageRect($hGraphics2, $hImage, $x, $y, $w, $h)
    $hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)

    ; set new image into list
    _GUIImageList_Add($hiList, $hHBMP)

    ; dispose objects
    _GDIPlus_ImageDispose($hBmp)
    _GDIPlus_GraphicsDispose($hGraphics2)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hHBMP)
Next

; dispose parent graphic
_GDIPlus_GraphicsDispose($hGraphics1)

; set image list to control
_GUICtrlListView_SetImageList($LV, $hiList)

For $i = 1 To $files[0]
    _GUICtrlListView_AddItem($LV, "file", $i)
Next

GUISetCursor()

Do
Until GUIGetMsg() == $GUI_EVENT_CLOSE

; final cleanup
_GUIImageList_Destroy($hiList)
_GDIPlus_Shutdown()

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites



NVM, i'm stupid today lol

Duh, use the proper function lol

Is it possible to add multiple images after the main image?

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $listview, $hImage
    
    GUICreate("ImageList AddBitmap", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState()
    
    ; Load images
    $hImage = _GUIImageList_Create(42, 42)
    _GUIImageList_AddBitmap($hImage, "personal.bmp")
    
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($listview, "Items", 120)

    ; Add items
    _GUICtrlListView_AddItem($listview, "Item 1", 0)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

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
Sign in to follow this  
Followers 0