ListIcon: LVM_INSERTITEM with lParam

Just starting out? Need help? Post your questions and find answers here.
wayne-c
Enthusiast
Enthusiast
Posts: 337
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

ListIcon: LVM_INSERTITEM with lParam

Post by wayne-c »

Any idea why the following code crashes when lParam is set to a value other than zero?

Code: Select all

If OpenWindow(0, 200, 200, 400, 400, "ListIcon", #PB_Window_SystemMenu)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(1, 10, 10, 300, 300, "Title", 100)
  EndIf
  Text.s= "Hello World"
  
  ;- When lParam is 0 everything works fine.
  ;- But try to set lParam to 10 (or any other value)
  ;- and the app crashes !!!
  lParam.l= 10
  
  var.LVITEM
  var\mask= #LVIF_TEXT | #LVIF_PARAM
  var\lParam= lParam
  var\iSubItem= 0
  var\pszText= @Text
  SendMessage_(GadgetID(1), #LVM_INSERTITEM, 0, @var)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I would guess that Purebasic uses it internally. If so, keep away! :D

**Edit: if you're just trying to set the item text, then remove the #LVIF_LPARAM.
I may look like a mule, but I'm not a complete ass.
wayne-c
Enthusiast
Enthusiast
Posts: 337
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Post by wayne-c »

srod wrote:I would guess that Purebasic uses it internally. If so, keep away! :D
@srod: wow, fast reply!

but why should PureBasic prevent me from setting this value? There is a PB function to set the lParam value (SetGadgetItemData()), but I want to have bigger icons than 32x32 so I need to use LVM_INSERTITEM (to set the iImage param to the index from an additional ImageList). I would be very happy if I could set lParam in the same call where I add the item. That even works in Visual Basic ;-)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Uhm, it works okay in PB3.94!

I can only think that it either is now interefering with PB internals, or it's a PB4 bug!

Only way to find out is to ask Freak or Fred.
I may look like a mule, but I'm not a complete ass.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

are you sure you need lParam in your case?!?

Platform SDK says:
  • lParam
    Value specific to the item. If you use the LVM_SORTITEMS message, the list-view control passes this value to the application-defined comparison function. You can also use the LVM_FINDITEM message to search a list-view control for an item with a specified lParam value.
i use the following code to set the image:

Code: Select all

Procedure AddItem(gadget.l, Row.l, Column.l, Text$, ImageIndex.l)
  Name$ = GetFilePart(Text$)
  var.LVITEM
  var\mask = #LVIF_IMAGE | #LVIF_TEXT
  var\iItem = Row         ; row number
  var\iSubItem = Column   ; subitem
  var\pszText = @Name$    ; text to set
  var\iImage = ImageIndex ; index of icon in the list
  SendMessage_(GadgetID(gadget), #LVM_INSERTITEM, 0, @var)
  SetGadgetItemText(gadget,Row,Text$,1)
EndProcedure
the imagelist must have been set...

Code: Select all

              Hwnd_ListNormal = ImageList_Create_(64,64,#ILC_MASK | #ILC_COLOR32, 0, 30)
              SendMessage_(GadgetID(#ListIconGadget1), #LVM_SETIMAGELIST, #LVSIL_NORMAL, Hwnd_ListNormal)
and/or

Code: Select all

              Hwnd_ListSmall = ImageList_Create_(32,32,#ILC_MASK | #ILC_COLOR32, 0, 30)
              SendMessage_(GadgetID(#ListIconGadget1), #LVM_SETIMAGELIST, #LVSIL_SMALL, Hwnd_ListSmall)

there is a nice example at http://purebasic.hmt-forum.com/viewtopic.php?t=692 handling imagelists...

;-) sverson
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

The lParam is now used by PB internally, you will have to use Set/GetGadgetItemData() in v4.
wayne-c
Enthusiast
Enthusiast
Posts: 337
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Post by wayne-c »

sverson wrote:are you sure you need lParam in your case?!?
@sverson: Thank you for your detailed reply! You are right, the lParam is not needed for the image-task. I need the lParam to link the item to a LinkedList where I store additional data for every item:

Code: Select all

Structure MyItemStruct
    Id.l               ; lParam
    FileName.s         ; this item's OS full file name, e.g. C:\data\test.txt
    iImage.l           ; Index of image in ImageList
    ...
EndStructure

Global NewList ListIconItems.MyItemStruct()
This way, whenever I have to deal with an item, I look in my LinkedList for the item (with the corresponding lParam) and get the additional data.

Of course I can use SetGadgetItemData (what I do now :wink: ), but because I anyway have to use #LVM_INSERTITEM (for the bigger image) I wanted to set the lParam at the same time.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

why dont you store your additional data in a (hidden) column?

here is a little example using two imagelists.

Code: Select all

removed! -> see next listing...
[EDIT] 8)

you can set the size of the big image in IconSize.l


;-) sverson
Last edited by sverson on Tue Jun 06, 2006 5:06 pm, edited 1 time in total.
wayne-c
Enthusiast
Enthusiast
Posts: 337
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Post by wayne-c »

sverson wrote:why dont you store your additional data in a (hidden) column?
This would work in "Large Icons" mode, but in "Details"-mode the row is not hidden, isn't it? Because I have to use both "Large" and "Details" view and the additional data contains data I definitely don0t want the user to see...

Or is there a way to hide a column in details mode? Just setting the length to 0 won0t work because the user still can resize the colwidth I think.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

wayne-c wrote:Or is there a way to hide a column in details mode?
yes!

Code: Select all

;/ 2006 sverson
;/ see also http://purebasic.hmt-forum.com/viewtopic.php?t=692
Global FilePath$, FileName$, IconSize.l=128

#MouseKlick  = -32767
Enumeration
  #MainWindow
  #ImageWindow
  #ListIconGadget1
  #Image
EndEnumeration

Enumeration
  #MenuNewBMPs
  #MenuMoreBMPs
  #MenuQuit
  #MenuBigIcons
  #MenuSmallIcons
  #MenuListModus
  #MenuReportModus
  #MenuBM64
  #MenuBM128
EndEnumeration

Procedure AddItem(gadget.l, Row.l, Column.l, Text$, ImageIndex.l)
  Name$ = GetFilePart(Text$)
  var.LVITEM
  var\mask     = #LVIF_IMAGE | #LVIF_TEXT
  var\iItem    = Row
  var\iSubItem = Column
  var\pszText  = @Name$
  var\iImage   = ImageIndex
  SendMessage_(GadgetID(gadget), #LVM_INSERTITEM, 0, @var)
  SetGadgetItemText(gadget,Row,Text$,1)
  SetGadgetItemText(gadget,Row,"hidden info 1/"+Str(Row),2)
  SetGadgetItemText(gadget,Row,"hidden info 2/"+Str(Row),3)
EndProcedure

Procedure LoadFiles(FileToLoad$)
  Protected MemImgNo.l, MemImgID.l, MemImgW.l, MemImgH.l, MemImgW1.l, MemImgH1.l, MemImgX.l, MemImgY.l, MemImgMul.f, TmpImgNo.l, TmpImgID.l, Extern.b
  Static Hwnd_ListSmall.l, Hwnd_ListNormal.l
  If FileToLoad$=""
    FileToLoad$ = OpenFileRequester("Bitmaps laden [MultiSelection]", FilePath$+"*.bmp","Bitmaps (bmp)|*.BMP"  , 0,#PB_Requester_MultiSelection)
    Extern=#False
  Else
    Extern=#True
  EndIf
  If FileToLoad$
    FilePath$=GetPathPart(FileToLoad$)
    Repeat
      If LCase(GetExtensionPart(FileToLoad$))="bmp"
        MemImgNo = LoadImage(#PB_Any,FileToLoad$)
        If MemImgNo And IsImage(MemImgNo)
          MemImgID = ImageID(MemImgNo)
          MemImgW  = ImageWidth(MemImgNo)
          MemImgH  = ImageHeight(MemImgNo)
          If MemImgH>MemImgW
            MemImgMul = IconSize/MemImgH
            MemImgW   = Int(MemImgW*MemImgMul)
            MemImgH   = Int(MemImgH*MemImgMul)
            MemImgX   = Int((IconSize-MemImgW)/2)
            MemImgY   = 0
          Else
            MemImgMul = IconSize/MemImgW
            MemImgW   = Int(MemImgW*MemImgMul)
            MemImgH   = Int(MemImgH*MemImgMul)
            MemImgX   = 0
            MemImgY   = Int((IconSize-MemImgH)/2)
          EndIf
          TmpImgNo = CreateImage(#PB_Any, IconSize, IconSize)
          TmpImgID = ImageID(TmpImgNo)
          StartDrawing(ImageOutput(TmpImgNo))
          Box(0,0,IconSize,IconSize,RGB($FF,$FF,$FF))
          DrawImage(MemImgID,MemImgX,MemImgY,MemImgW,MemImgH)
          StopDrawing()
          If CountGadgetItems(#ListIconGadget1)=0
            Hwnd_ListNormal = ImageList_Create_(IconSize,IconSize,#ILC_MASK | #ILC_COLOR32, 0, 30)
            SendMessage_(GadgetID(#ListIconGadget1), #LVM_SETIMAGELIST, #LVSIL_NORMAL, Hwnd_ListNormal)
          EndIf
          IndexImage=ImageList_Add_(Hwnd_ListNormal,TmpImgID,0)
          ResizeImage(TmpImgNo,32,32)
          TmpImgID = ImageID(TmpImgNo)
          If CountGadgetItems(#ListIconGadget1)=0
            Hwnd_ListSmall = ImageList_Create_(32,32,#ILC_MASK | #ILC_COLOR32, 0, 30)
            SendMessage_(GadgetID(#ListIconGadget1), #LVM_SETIMAGELIST, #LVSIL_SMALL, Hwnd_ListSmall)
          EndIf
          IndexImage=ImageList_Add_(Hwnd_ListSmall,TmpImgID,0)
          AddItem(#ListIconGadget1,CountGadgetItems(#ListIconGadget1),0,FileToLoad$,IndexImage)
          FreeImage(MemImgNo)
          FreeImage(TmpImgNo)
        EndIf
      EndIf
      If Extern
        FileToLoad$ = ProgramParameter()
      Else
        FileToLoad$ = NextSelectedFileName()   
      EndIf
    Until FileToLoad$ = ""                         
  EndIf
EndProcedure

Procedure ShowImage(ImgPath.s)
  Protected TmpImgNo.l, TmpImgID.l
  TmpImgNo = LoadImage(#PB_Any,ImgPath)
  If TmpImgNo
    TmpImgID = ImageID(TmpImgNo)
    If OpenWindow(#ImageWindow, 0, 0, ImageWidth(TmpImgNo), ImageHeight(TmpImgNo), "Bitmap FileView (*.bmp)", #PB_Window_ScreenCentered | #PB_Window_SystemMenu,WindowID(#MainWindow))
      If CreateGadgetList(WindowID(#ImageWindow))
        ImageGadget(#PB_Any,0,0,ImageWidth(TmpImgNo),ImageHeight(TmpImgNo),TmpImgID)
      EndIf
      Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
      CloseWindow(#ImageWindow)
    EndIf
    FreeImage(TmpImgNo)
  EndIf
EndProcedure

Procedure WindowCallBack(Window, message, wParam, lParam);- Window Callback
  ;/ ...to get more information see:
  ;/ Tricks 'n' Tips: 12.10.2004 08:06   
  ;/                  listicon Header : captured Or released
  ;/                  http://jconserv.net/purebasic/viewtopic.php?t=12751&highlight=Header+listicon
  ;/                  by eddy
  ;/ modified:        04.02.1005 sverson
  
  Protected wWidth.l, wHeight.l, Gadget_ID.l, AktColumn.l, LastColumn.l
  ReturnValue = #PB_ProcessPureBasicEvents
  Select message
    Case #WM_NOTIFY
      *nmHEADER.HD_NOTIFY = lParam
      Gadget_ID = *nmHEADER\hdr\hwndFrom
      Select *nmHEADER\hdr\code
        Case #HDN_ITEMCHANGING ; is header item changing?
          Select GetParent_(Gadget_ID)
            Case GadgetID(#ListIconGadget1)
              If *nmHEADER\iItem = 2 ; col fixed "Hidden 1"
                Beep_(1000,50)
                ReturnValue = #True
              EndIf
              If *nmHEADER\iItem = 3 ; col fixed "Hidden 2"
                Beep_(1200,50)
                ReturnValue = #True
              EndIf
          EndSelect
      EndSelect 
  EndSelect
  ProcedureReturn ReturnValue
EndProcedure


FileName$ = ProgramParameter()

If OpenWindow(#MainWindow, 0, 0, 670, 520, "Bitmap Filelister (*.bmp)", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  If CreateGadgetList(WindowID(#MainWindow))
    ListIconGadget(#ListIconGadget1, 10, 10, 650, 480, "BMP-Datei",150,#PB_ListIcon_FullRowSelect);|#LVS_NOCOLUMNHEADER);|#PB_ListIcon_GridLines
    ChangeListIconGadgetDisplay(#ListIconGadget1, #PB_ListIcon_Report)
    AddGadgetColumn(#ListIconGadget1, 1, "Pfad", 480)
    AddGadgetColumn(#ListIconGadget1, 2, "Hidden 1", 0)
    AddGadgetColumn(#ListIconGadget1, 3, "Hidden 2", 0)
    
    ;/ un petit menu
    If CreateMenu(0,WindowID(#MainWindow))
      MenuTitle("&Datei")
      MenuItem(#MenuNewBMPs,"BMPs neu &laden...")
      MenuItem(#MenuMoreBMPs,"BMPs &nachladen...")
      MenuBar()
      MenuItem(#MenuQuit,"&Ende")
      MenuTitle("&Anzeige")
      MenuItem(#MenuBigIcons,"&Kacheln") : DisableMenuItem(0,#MenuBigIcons,#True)
      MenuItem(#MenuSmallIcons,"&Symbole")
      MenuItem(#MenuListModus,"&Liste")
      MenuItem(#MenuReportModus,"&Details")
      ; MenuTitle("&Größe")
      ; MenuItem(#MenuBM64,"&64x64") : SetMenuItemState(0,#MenuBM64,1)
      ; MenuItem(#MenuBM128,"&128x128")
    EndIf   
    
    SetWindowCallback(@WindowCallBack())    
    
    Repeat
      If FileName$<>""
        LoadFiles(FileName$)
        FileName$=""
      EndIf
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit=1
        Case #PB_Event_Menu
          Select EventMenu()
            ;/Partie
            Case #MenuQuit : Quit=1
            Case #MenuNewBMPs
              ClearGadgetItemList(#ListIconGadget1) 
              LoadFiles("")
            Case #MenuMoreBMPs
              LoadFiles("")
            Case #MenuBigIcons
              ChangeListIconGadgetDisplay(#ListIconGadget1, 0)
              DisableMenuItem(0,#MenuBigIcons,#True)
              DisableMenuItem(0,#MenuSmallIcons,#False)
              DisableMenuItem(0,#MenuListModus,#False)
              DisableMenuItem(0,#MenuReportModus,#False)
            Case #MenuSmallIcons
              ChangeListIconGadgetDisplay(#ListIconGadget1, 1)
              DisableMenuItem(0,#MenuBigIcons,#False)
              DisableMenuItem(0,#MenuSmallIcons,#True)
              DisableMenuItem(0,#MenuListModus,#False)
              DisableMenuItem(0,#MenuReportModus,#False)
            Case #MenuListModus
              ChangeListIconGadgetDisplay(#ListIconGadget1, 2)
              DisableMenuItem(0,#MenuBigIcons,#False)
              DisableMenuItem(0,#MenuSmallIcons,#False)
              DisableMenuItem(0,#MenuListModus,#True)
              DisableMenuItem(0,#MenuReportModus,#False)
            Case #MenuReportModus
              ChangeListIconGadgetDisplay(#ListIconGadget1, 3)
              DisableMenuItem(0,#MenuBigIcons,#False)
              DisableMenuItem(0,#MenuSmallIcons,#False)
              DisableMenuItem(0,#MenuListModus,#False)
              DisableMenuItem(0,#MenuReportModus,#True)
          EndSelect   
        Default
          If GetAsyncKeyState_(#VK_LBUTTON) = #MouseKlick
            ShowImage(GetGadgetItemText(#ListIconGadget1,GetGadgetState(#ListIconGadget1),1))
          EndIf
          If GetAsyncKeyState_(#VK_RBUTTON) = #MouseKlick
            aktPos = GetGadgetState(#ListIconGadget1)
            OldPath$ = GetPathPart(GetGadgetItemText(#ListIconGadget1,aktPos,1))
            Oldfile$ = GetGadgetItemText(#ListIconGadget1,aktPos,0)
            Newfile$ = InputRequester("Rename File",OldPath$,Oldfile$)
            If RenameFile(OldPath$+Oldfile$,OldPath$+Newfile$)
              SetGadgetItemText(#ListIconGadget1,aktPos,Newfile$,0)
              SetGadgetItemText(#ListIconGadget1,aktPos,OldPath$+Newfile$,1)
            Else
              Beep_(100,100)
            EndIf
          EndIf
      EndSelect
    Until Quit
    
  EndIf
EndIf

ImageList_Destroy_(Hwnd_ListNormal)
ImageList_Destroy_(Hwnd_ListSmall)
End
in this example column 2 and 3 are fixed to columnwidth=0

;-) sverson
Post Reply