[Windows] Listview background image

Just starting out? Need help? Post your questions and find answers here.
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

[Windows] Listview background image

Post by Fenix »

Hi @all,

I'm trying to set a background image to a listview (PB: listicon). But it won't work :evil:
I'm pretty sure I got the LVBKIMAGE structure right, I also implemented the CoInitialize_() but still the picture's a no show.

Code: Select all

Structure LVBKIMAGE 
  ulFlags.l             ; ULONG
  hbm.l                 ; HBITMAP
  pszImage.l            ; LPSTR
  cchImageMax.l         ; UINT -> long
  xOffsetPercent.l      ; INT
  yOffsetPercent.l      ; INT -> long
EndStructure

; LV BACKGROUND IMAGE
#LVBKIF_SOURCE_NONE     = $0
#LVBKIF_SOURCE_HBITMAP  = $1
#LVBKIF_SOURCE_URL      = $2
#LVBKIF_STYLE_NORMAL    = $0
#LVBKIF_TYPE_WATERMARK  = $10000000
#LVBKIF_FLAG_ALPHABLEND = $20000000


Global _lvBkImage.LVBKIMAGE

Procedure listviewSetBackgroundImage(iGadget.i, handleImage.i)
  ; --- sets a background image (ihandleImage) to a listview (iGadget)
  
  Debug SizeOf(LVBKIMAGE)
  Debug "setting lv bkimage"
  
  FillMemory(@_lvBkImage, SizeOf(LVBKIMAGE))                          ; clear the structure
  _lvBkImage\ulFlags        = #LVBKIF_SOURCE_HBITMAP | #LVBKIF_STYLE_NORMAL
  _lvBkImage\hbm            = handleImage
  _lvBkImage\xOffsetPercent = 50
  _lvBkImage\yOffsetPercent = 50
  
  SendMessage_(iGadget, #LVM_SETBKIMAGE, #Null, @_lvBkImage)
EndProcedure


If OpenWindow(0, 10, 10, 500, 400, "LV - BK IMAGE", #PB_Window_SystemMenu |#PB_Window_WindowCentered |#PB_Window_ScreenCentered)
  handleListView.i = ListIconGadget(#PB_Any, 10, 10, 490, 390, "LV TEST", 100)
  CoInitialize_(#Null)
  UsePNGImageDecoder()
  handleImage.i = CatchImage(#PB_Any, ?IMAGE, ?IMAGEEND - ?IMAGE)
  If handleImage
    listviewSetBackgroundImage(GadgetID(handleListView), ImageID(handleImage))
  EndIf
  
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  CoUninitialize_()
EndIf

End

IMAGE:
IncludeBinary "c:\temp\picture.png"
IMAGEEND:
Where am I wrong?? I'm still confused with the windows datatypes. The LVBKIMAGE structure sets the bitmap handle (hbm) to long, which is 32 bit (afaik). But the handles on a 64bit OS should be 64bit, right (I'm using Win7 64)?

Thanx!
Fenix
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5015
Joined: Sun Apr 12, 2009 6:27 am

Re: [Windows] Listview background image

Post by RASHAD »

Add

Code: Select all

UsePNGImageDecoder()
Egypt my love
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

Re: [Windows] Listview background image

Post by Fenix »

RASHAD wrote:Add

Code: Select all

UsePNGImageDecoder()
Hi RASHAD,

I do (right before i catch the image) :wink:

Greetz,
Fenix
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5015
Joined: Sun Apr 12, 2009 6:27 am

Re: [Windows] Listview background image

Post by RASHAD »

Sorry Fenix :mrgreen:
I noticed it later
Try the next code and make sure that your image is loadable first
and tell us the result
Tested with 5.20 x86 win 8.1 x64 with another image

Code: Select all

UsePNGImageDecoder()

Structure LVBKIMAGE
  ulFlags.l             ; ULONG
  hbm.l                 ; HBITMAP
  pszImage.l            ; LPSTR
  cchImageMax.l         ; UINT -> long
  xOffsetPercent.l      ; INT
  yOffsetPercent.l      ; INT -> long
EndStructure

; LV BACKGROUND IMAGE
#LVBKIF_SOURCE_NONE     = $0
#LVBKIF_SOURCE_HBITMAP  = $1
#LVBKIF_SOURCE_URL      = $2
#LVBKIF_STYLE_NORMAL    = $0
#LVBKIF_TYPE_WATERMARK  = $10000000
#LVBKIF_FLAG_ALPHABLEND = $20000000

Global _lvBkImage.LVBKIMAGE

Procedure listviewSetBackgroundImage(iGadget.i, handleImage.i)
  ; --- sets a background image (ihandleImage) to a listview (iGadget)
 
  Debug SizeOf(LVBKIMAGE)
  Debug "setting lv bkimage"
 
  ;FillMemory(@_lvBkImage, SizeOf(LVBKIMAGE))                          ; clear the structure
  _lvBkImage\ulFlags        = #LVBKIF_SOURCE_HBITMAP | #LVBKIF_STYLE_NORMAL 
  _lvBkImage\hbm            = handleImage
  _lvBkImage\xOffsetPercent = 50
  _lvBkImage\yOffsetPercent = 50
 
  SendMessage_(iGadget, #LVM_SETBKIMAGE, #Null, @_lvBkImage)
EndProcedure

If OpenWindow(0, 10, 10, 500, 400, "LV - BK IMAGE", #PB_Window_SystemMenu |#PB_Window_WindowCentered |#PB_Window_ScreenCentered)
  handleListView.i = ListIconGadget(#PB_Any, 10, 10, 490, 390, "LV TEST", 100)
  ;CoInitialize_(#Null)  
  handleImage = CatchImage(#PB_Any, ?IMAGE, ?IMAGEEND - ?IMAGE)
  If handleImage
    listviewSetBackgroundImage(GadgetID(handleListView), ImageID(handleImage))
  EndIf
 
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  ;CoUninitialize_()
EndIf

End

IMAGE:
IncludeBinary "c:\temp\picture.png"
IMAGEEND:
Egypt my love
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

Re: [Windows] Listview background image

Post by Fenix »

RASHAD wrote:Sorry Fenix :mrgreen:
I noticed it later
Try the next code and make sure that your image is loadable first
and tell us the result
Tested with 5.20 x86 win 8.1 x64 with another image
I did, but still it's a no show :? (I tried with two different pictures and also tried two jpeg [then of course with UseJPEGDecoder()])

What do you mean by "make sure that your image is loadable first"?

P.S. I run Win7, 64bit, fresh installation with all updates.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: [Windows] Listview background image

Post by ts-soft »

Change the structure to:

Code: Select all

Structure LVBKIMAGE Align #PB_Structure_AlignC 
  ulFlags.l             ; ULONG
  hbm.i                 ; HBITMAP -> handle, integer
  pszImage.i            ; LPSTR -> pointer, integer
  cchImageMax.l         ; UINT -> long
  xOffsetPercent.l      ; INT
  yOffsetPercent.l      ; INT -> long
EndStructure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

Re: [Windows] Listview background image

Post by Fenix »

@ts-soft: YES!! :mrgreen: That's it. Thank you!

[And I had the right suspicion, it's been the structure (well, the datatypes on 32/64 bit)]

Greetz,
Fenix
Post Reply