Sign in to follow this  
Followers 0
AntiFros

How to easly make list with images?

12 posts in this topic

#1 ·  Posted (edited)

I were trying normal way to create image list but it didnt worked and it were too complex.

I need list like ListBox but with images too.

Is there any easy function or UDF where adding list would be like writing some func  addList("image.png","Line text") ?

Making image lists with those funcs are very messy. I need really big list and I will need to manage it alot.

 

Images for example :

Jegd7vMb5lV.pngHGdGnr7OGkc.png4WpaX_R-VnQ.pngnyGEC6hOf9m.png

they might be bigger or smaller. How I want my list too look like (paint) -

is8102j.png

 

 

 

 

 

 

Last edit: everything works.. just images not converted properly..

Edited by AntiFros

Share this post


Link to post
Share on other sites



I saw example code but I dont understand how it works.  How to make one column  with my images? I see there only created bitmaps

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#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()
    $hImage = _GUIImageList_Create(42, 42)
    _GUIImageList_AddBitmap($hImage, @ScriptDir &"test.bmp")
    _GUICtrlListView_SetImageList($listview, $hImage, 1)
    _GUICtrlListView_AddColumn($listview, "Items", 120)
    _GUICtrlListView_AddItem($listview, "Item 1", 0)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Wont work..

test.bmp -> 4WpaX_R-VnQ.png (save as .bmp)

 

 

 

 

 

 

---------------------------------------------

Ok found this nice way. It work fine for now.

Edit: nah dont work when I want to add more than one.. Always same pic

#Include <GDIPlus.au3>
#Include <GUIImageList.au3>
#Include <GUIListView.au3>

_GDIPlus_Startup()

$hForm = GUICreate('MyGUI', 400, 400, 302, 218)
$hListView = GUICtrlCreateListView('', 10, 10, 380, 380)
_GUICtrlListView_AddColumn($hListView, 'Items', 200)
$hImageList = _GUIImageList_Create(15, 16, 5, 1)
_GUICtrlListView_SetImageList($hListView, $hImageList, 1)
_GUIImageList_AddImage($hImageList, -1, @ScriptDir & '\test.bmp')
_GUICtrlListView_AddItem($hListView, 'Testassss', 0)

GUISetState()












Do
Until GUIGetMsg() = -3

Func _GUIImageList_AddImage($hWnd, $iIndex, $sFile)

    Local $Size = _GUIImageList_GetIconSize($hWnd)

    If (Not $Size[0]) Or (Not $Size[1]) Then
        Return -1
    EndIf

    Local $W, $H, $hGraphic, $hPic, $hImage, $hIcon

    _GDIPlus_Startup()
    $hPic = _GDIPlus_ImageLoadFromFile($sFile)
    $W = _GDIPlus_ImageGetWidth($hPic)
    $H = _GDIPlus_ImageGetHeight($hPic)
    If ($W < 0) Or ($H < 0) Then
        _GDIPlus_Shutdown()
        Return -1
    EndIf
    If $W < $H Then
        $W = $Size[0] * $W / $H
        $H = $Size[1]
    Else
        $H = $Size[1] * $H / $W
        $W = $Size[0]
    EndIf
    $hImage = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hPic, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage[4])
    _GDIPlus_GraphicsClear($hGraphic, 0)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPic, ($Size[0] - $W) / 2, ($Size[1] - $H) / 2, $W, $H)
    $hIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'ptr', $hImage[4], 'ptr*', 0)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage[4])
    _GDIPlus_ImageDispose($hPic)
    _GDIPlus_Shutdown()
    If Not $hIcon[2] Then
        Return -1
    EndIf
    $iIndex = _GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon[2])
    _WinAPI_DestroyIcon($hIcon[2])
    Return $iIndex
EndFunc   ;==>_GUIImageList_AddImag
Edited by AntiFros

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In your first example you had these bugs:

$hImage = _GUIImageList_Create(42, 42) ; -> should be 20
_GUIImageList_AddBitmap($hImage, @ScriptDir &"test.bmp") ; -> missing \

correct:

$hImage = _GUIImageList_Create(20, 20)
_GUIImageList_AddBitmap($hImage, @ScriptDir &"\test.bmp")

Also your image must be bitmap not PNG file! (check it internally not only by its extension)

After these fixes all works fine.

Edited by Zedna

Share this post


Link to post
Share on other sites

 

Edit: nah dont work when I want to add more than one.. Always same pic

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $listview, $hImage
    Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    GUICreate("ImageList Add", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(11, 11)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, [PATH TO IMAGE 1], 11, 11))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, [PATH TO IMAGE 2], 11, 11))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, [PATH TO IMAGE 3], 11, 11))
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

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

    ; Add items
    _GUICtrlListView_AddItem($listview, "Item 1", 0); WILL USE IMAGE 1 BECAUSE IT IS THE FIRST INDEX OF 0
    _GUICtrlListView_AddItem($listview, "Item 2", 1) ; WILL USE IMAGE 2 BECAUSE IT IS THE SECOND INDEX OF 1
    _GUICtrlListView_AddItem($listview, "Item 3", 2); WILL USE IMAGE 3 BECAUSE IT IS THE THIRD INDEX OF 2

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

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Here an example you can start with: 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Thanks for help. Now I can make list with images easly. The main problem was that I used renamed png pictures and no real bmp.

Now how to manage my list easly? With those indexes are too complex.

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$_1 = GUICreate("ImageList AddBitmap", 400, 339, 264, 129)
    $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(@SW_SHOW)
$image = GUICtrlCreateInput("fb.bmp", 8, 296, 177, 21)
$name = GUICtrlCreateInput("Test", 192, 296, 73, 21)
$add = GUICtrlCreateButton("add", 280, 296, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Load images
   global $hImage = _GUIImageList_Create(15, 15)
    _GUIImageList_AddBitmap($hImage,"1.bmp")
   _GUIImageList_AddBitmap($hImage, "2.bmp")
    _GUIImageList_AddBitmap($hImage,"3.bmp")
   _GUIImageList_AddBitmap($hImage,"4.bmp")
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($listview, "  Y", 150)
    ; Add items
    _GUICtrlListView_AddItem($listview, "1", 0)
    _GUICtrlListView_AddItem($listview, "2", 1)
    _GUICtrlListView_AddItem($listview, "3", 2)
   _GUICtrlListView_AddItem($listview, "4", 3)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $add
            addItem(GUICtrlRead($image),GUICtrlRead($name))
    EndSwitch
WEnd



Func addItem($image,$name)
    _GUIImageList_AddBitmap($hImage,$image)
    _GUICtrlListView_AddItem($listview, $name, 0)  ;how to manage those indexes???
Endfunc

Also I need to delete or transfer some entries to another list..

 

Rar pack to do tests. bmp images included. V

 

list.rar

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Look at my script, test it and you will see.

I want to add my list ouside script. In this case I made GUI to show you. So how I need to pair image and text?

Inside script you just can do this

 _GUIImageList_AddBitmap($hImage,$image)
 _GUICtrlListView_AddItem($listview, $name, [index])

but how to do it ouside script? When I only have image and item name.

Edited by AntiFros

Share this post


Link to post
Share on other sites

In that case your line of

_GUIImageList_AddBitmap($hImage,$image)

Should use the path you return when searching for the $image.  Try using the FileOpenDialog with a filter for *.bmp files to grab an image. 


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Im talking not about _GUIImageList_AddBitmap($hImage,$image)..

About

 _GUICtrlListView_AddItem($listview, $name, [index])

Download my attached file "list.rar" run script and try to add new content with different pictures. The pic always be the same because it needs index. So I need to pair it.  

Yeah It can be written by hand in code but I will need to have over 300 images with text in list..

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