Page 1 of 1

[Windows] Listview background image

Posted: Wed Mar 12, 2014 12:32 pm
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

Re: [Windows] Listview background image

Posted: Wed Mar 12, 2014 12:50 pm
by RASHAD
Add

Code: Select all

UsePNGImageDecoder()

Re: [Windows] Listview background image

Posted: Wed Mar 12, 2014 1:01 pm
by Fenix
RASHAD wrote:Add

Code: Select all

UsePNGImageDecoder()
Hi RASHAD,

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

Greetz,
Fenix

Re: [Windows] Listview background image

Posted: Wed Mar 12, 2014 1:30 pm
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:

Re: [Windows] Listview background image

Posted: Wed Mar 12, 2014 1:53 pm
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.

Re: [Windows] Listview background image

Posted: Wed Mar 12, 2014 2:03 pm
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

Re: [Windows] Listview background image

Posted: Wed Mar 12, 2014 3:40 pm
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