Adding a 16x16 image to a column of a listicongadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Adding a 16x16 image to a column of a listicongadget

Post by marcoagpinto »

Hi!

I have a listicongadget with several columns.

The command:
SetGadgetItemImage(#LISTGADGET_TYPES,1,ImageID(20083))
always adds the image to the beginning of the row number 1.

But, I wanted to add it to a certain column inside each row.

Is there a way of doing it?

Thanks!

Kind regards,
>Marco A.G.Pinto
---------------
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Adding a 16x16 image to a column of a listicongadget

Post by RASHAD »

Sorry for Windows only
- You can add image with any size to Column Header
- You can add image with any size to any Column at any Raw
- Use your own images

Code: Select all

#HDF_BITMAP_ON_RIGHT = 4096 
#HDF_IMAGE           = 2048 
#HDF_STRING          = 16384 
#HDI_TEXT            = 2 
#HDI_IMAGE           = 32 
#HDI_FORMAT          = 4 

Global oldproc, header_h

Procedure InsertImg(Row,Col,Img)
  var.lv_item    
  Var\mask     =  #LVIF_IMAGE
  Var\iItem    = Row
  Var\iSubItem = Col
  Var\iImage   = Img ;Index of image in the list
  SendMessage_(GadgetID(0), #LVM_SETITEM, 0, @Var)
EndProcedure


Procedure SetHeaderImage(Header,Col)             
  VarHeader.HDITEM
  VarHeader\mask = #HDI_IMAGE
  VarHeader\fmt = #HDF_IMAGE
  VarHeader\iImage = 1 
  SendMessage_(Header , #HDM_SETITEM, Col, @VarHeader)
EndProcedure 

Procedure Hheight(hwnd, msg, wParam, lParam)
   Select msg
      Case #HDM_LAYOUT 
        result = CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
        *hdlayout.HD_LAYOUT = lParam
        If *hdlayout\prc <> 0
            *rect.RECT = *hdlayout\prc
            *rect\top = header_h
        EndIf
        If *hdlayout\pwpos <> 0
            *windowpos.WINDOWPOS = *hdlayout\pwpos
            *windowpos\cy = header_h
        EndIf
      
      Default
        result = CallWindowProc_(oldproc, hWnd, Msg, wParam, lParam)
    
    EndSelect
    ProcedureReturn result
EndProcedure

LoadImage(10,"g:\image4.bmp")   ;Use your Own Image
LoadImage(20,"g:\image5.bmp")   ;Use your Own Image

CreateImage(0,32,32)
CreateImage(1,32,32)
StartDrawing(ImageOutput(1))
  DrawImage(ImageID(10),2,2,28,28)
StopDrawing()

iinf.ICONINFO
iinf\hbmMask = ImageID(0)
iinf\hbmColor = ImageID(1)

Icwnd = CreateIconIndirect_(iinf)

CreateImage(2,32,32)
CreateImage(3,32,32)
StartDrawing(ImageOutput(3))
  DrawImage(ImageID(20),2,2,28,28)
StopDrawing()

iinf\hbmMask = ImageID(2)
iinf\hbmColor = ImageID(3)

Icwnd2 = CreateIconIndirect_(iinf)

For Img = 0 To 3
   FreeImage(Img)
Next

LoadFont(0,"Broadway",16)

OpenWindow(0,0,0,800,600, "Test", #PB_Window_ScreenCentered |#PB_Window_SystemMenu)       
ListIconGadget(0,10,10,780,540,"Column 1",250,#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
;SetGadgetColor(0,#PB_Gadget_LineColor,0)
SetGadgetFont(0,FontID(0)) 
AddGadgetColumn(0, 1, "Column 2",250) 
AddGadgetColumn(0, 2, "Column 3",255) 

SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE , #LVS_EX_SUBITEMIMAGES, #LVS_EX_SUBITEMIMAGES)

ILwnd = ImageList_Create_(32,32,#ILC_COLOR32| #ILC_MASK, 0, 100)
ImageList_AddIcon_(ILwnd,Icwnd)
ImageList_AddIcon_(ILwnd,Icwnd2)

SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
For i = 0 To 5 
  AddGadgetItem(0, -1, "111"+Chr(10)+ "222"+Chr(10)+"333"+ Chr(10) + "444",0) 
Next

ButtonGadget(1,10,570,60,24,"Insert") 
ButtonGadget(2,80,570,60,24,"Change")

oldproc = SetWindowLong_(Header, #GWL_WNDPROC, @Hheight())
;InsertImg(0,1,0)
Image = 1
header_h = 32

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
                SetHeaderImage(Header,1)
                InsertImg(0,1,1)
                InsertImg(0,2,1)
                InsertImg(3,2,1)
                
           Case 2
                Image ! 1
                InsertImg(0,1,Image)
                InsertImg(3,2,Image)
                
          EndSelect             
  EndSelect 

Until Quit = 1
End
Egypt my love
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Adding a 16x16 image to a column of a listicongadget

Post by marcoagpinto »

@RASHAD

Buaaaaaaaa... so much code to just place one little 16x16 image?! :shock:

Where is Fredddy?! :oops: :cry:

Fredddy?!?!? Is there a way of doing it with 5.30? :evil: :twisted: :!: :?: :idea:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Adding a 16x16 image to a column of a listicongadget

Post by PB »

> so much code to just place one little 16x16 image?!

That's the nature of coding on Windows. I see it all the time.
Sometimes it's 1 KB of code just to replace a char in a string.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Adding a 16x16 image to a column of a listicongadget

Post by Fangbeast »

Thanks for this new example RASHAD, much appreciated and !!Snagged!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Adding a 16x16 image to a column of a listicongadget

Post by RASHAD »

Hi Fangles
I wish you my best wishes my friend
The client not satisfied (marcoagpinto) :mrgreen:
Egypt my love
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Adding a 16x16 image to a column of a listicongadget

Post by marcoagpinto »

I don't want to sound annoying... but, can't Fred grab the code supplied by RASHAD and create a command that uses it?

Thanks RASHAD, I am sorry for being aggressive while you were trying to help!!!!

I know you were trying to help the best way possible!

Kind regards,
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Adding a 16x16 image to a column of a listicongadget

Post by RASHAD »

Do not be sorry marco
Sorry for whate
I am just joking :P
Egypt my love
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Adding a 16x16 image to a column of a listicongadget

Post by Danilo »

marcoagpinto wrote:I don't want to sound annoying... but, can't Fred grab the code supplied by RASHAD and create a command that uses it?
Nope. Fred would need to make sure it works on the other two supported platforms too.
He also needs to think about it with possible future platforms in mind. Is it a common
thing on many/most platforms, or is it a relative seldom thing on one or two platforms only.
Third, if supported, he needs to write it for the other platforms or create a hack that makes
it possible, if not directly supported by the OS. In this case, he also needs to pay attention to possible
future compatibility problems for the specific OS. It is not that easy, Marco. ;)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Adding a 16x16 image to a column of a listicongadget

Post by Fangbeast »

Hi Fangles
Hello RASHAD, how is life?
I wish you my best wishes my friend
Thank you and the same to you.
The client not satisfied (marcoagpinto) :mrgreen:
He is an exciteable young fellow:):)

RASHAD, I need your advice. At the moment, I use code below I found in the forums to change icons in any column, no further perparation. It made it easy to procedurise it and re-use it. All my icons are loaded into from constants into a structure. Then the imagelist is created of course. (Big one!!)

..Can your code work with icons or only BMP files? (Want to use existing 32x32 icons)
..How do you remove the black border from the image?

Code: Select all

; Update each collumn of a ListIconGadget with a user defined icon as needed
Procedure ChangeIcon(MyGadget.i, MyRow.i, MyColumn.i, MyIcon.i)
  LVG.lv_item      
  LVG\mask     = #LVIF_IMAGE | #LVIF_TEXT 
  LVG\iItem    = MyRow.i
  LVG\iSubItem = MyColumn.i
  ChangeText.s = GetGadgetItemText(MyGadget.i, MyRow.i, MyColumn.i)
  LVG\pszText  = @ChangeText.s
  LVG\iImage   = MyIcon.i
  SendMessage_(GadgetID(MyGadget.i), #LVM_SETITEM, 0, @LVG) 
  ;
EndProcedure

ChangeIcon(#MyGadgetName, LineNumber, ColumnToChange, Program\Abusiness)

My event manager looks nice but you have given me the idea for making everything bigger and more recogniseable for my bad eyes.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Adding a 16x16 image to a column of a listicongadget

Post by RASHAD »

Hi Fangles
..Can your code work with icons
Yes and also with any size

Code: Select all

#HDF_BITMAP_ON_RIGHT = 4096
#HDF_IMAGE           = 2048
#HDF_STRING          = 16384
#HDI_TEXT            = 2
#HDI_IMAGE           = 32
#HDI_FORMAT          = 4

Global oldproc, header_h

Procedure InsertImg(Row,Col,Img)
  var.lv_item   
  Var\mask     =  #LVIF_IMAGE
  Var\iItem    = Row
  Var\iSubItem = Col
  Var\iImage   = Img ;Index of image in the list
  SendMessage_(GadgetID(0), #LVM_SETITEM, 0, @Var)
EndProcedure

Procedure SetHeaderImage(Header,Col)             
  VarHeader.HDITEM
  VarHeader\mask = #HDI_IMAGE
  VarHeader\fmt = #HDF_IMAGE
  VarHeader\iImage = 1
  SendMessage_(Header , #HDM_SETITEM, Col, @VarHeader)
EndProcedure

Procedure Hheight(hwnd, msg, wParam, lParam)
   Select msg
      Case #HDM_LAYOUT
        result = CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
        *hdlayout.HD_LAYOUT = lParam
        If *hdlayout\prc <> 0
            *rect.RECT = *hdlayout\prc
            *rect\top = header_h
        EndIf
        If *hdlayout\pwpos <> 0
            *windowpos.WINDOWPOS = *hdlayout\pwpos
            *windowpos\cy = header_h
        EndIf
     
      Default
        result = CallWindowProc_(oldproc, hWnd, Msg, wParam, lParam)
   
    EndSelect
    ProcedureReturn result
EndProcedure

LoadFont(0,"Broadway",16)

OpenWindow(0,0,0,800,600, "Test", #PB_Window_ScreenCentered |#PB_Window_SystemMenu)       
ListIconGadget(0,10,10,780,540,"Column 1",250,#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)

SetGadgetFont(0,FontID(0))
AddGadgetColumn(0, 1, "Column 2",250)
AddGadgetColumn(0, 2, "Column 3",255)

SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE , #LVS_EX_SUBITEMIMAGES, #LVS_EX_SUBITEMIMAGES)

ILwnd = ImageList_Create_(64,64,#ILC_COLOR32| #ILC_MASK, 0, 100)

;*************************************************************
ico_1 = LoadImage_(0,"e:\child.ico",#IMAGE_ICON,64,64,#LR_LOADFROMFILE	)    ;Load your own icon file
ico_2 = LoadImage_(0,"e:\copy.ico",#IMAGE_ICON,64,64,#LR_LOADFROMFILE	)    ;Load your own icon file
;*************************************************************

ImageList_AddIcon_(ILwnd,ico_1)
ImageList_AddIcon_(ILwnd,ico_2)

SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
For i = 0 To 5
  AddGadgetItem(0, -1, "111"+Chr(10)+ "222"+Chr(10)+"333"+ Chr(10) + "444",0)
Next

ButtonGadget(1,10,570,60,24,"Insert")
ButtonGadget(2,80,570,60,24,"Change")

oldproc = SetWindowLongPtr_(Header, #GWL_WNDPROC, @Hheight())

Image = 1
header_h = 64

Repeat
  Select WaitWindowEvent()
     
      Case #PB_Event_CloseWindow
            Quit = 1
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
                SetHeaderImage(Header,1)
                InsertImg(0,1,1)
                InsertImg(0,2,1)
                InsertImg(3,2,1)
               
           Case 2
                Image ! 1
                InsertImg(0,1,Image)
                InsertImg(3,2,Image)
               
          EndSelect             
  EndSelect

Until Quit = 1
End
..How do you remove the black border from the image?

Code: Select all

StartDrawing(ImageOutput(1))
  Box(0,0,32,32,#White)     ;Added to remove the black border
  DrawImage(ImageID(10),2,2,28,28)
StopDrawing()
And only for you Fangles :P
Create your own ICON and CURSOR
http://www.purebasic.fr/english/viewtop ... 12&t=59815
Egypt my love
Post Reply