Background image in listicon, how to set 0, 0 pos?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

Using RASHAD's code here to set a background image in a Listicongadget. The image is shown just fine but how do I set it so it starts at position 0,0 (X/Y) in the gadget?

It's showing about 2 inches across and an inch and a half down?

Code: Select all

; Set a background image in a ListIconGadget - RASHAD

CoInitialize_(0)

; Constants

Enumeration
   #LVBKIF_SOURCE_NONE
   #LVBKIF_SOURCE_HBITMAP
   #LVBKIF_SOURCE_URL
   #LVBKIF_SOURCE_MASK
EndEnumeration

#LVBKIF_STYLE_TILE      = 16
#LVBKIF_FLAG_TILEOFFSET = 256
#LVBKIF_TYPE_WATERMARK  = $10000000
#LVBKIF_STYLE_NORMAL    = 0
#LVS_EX_DOUBLEBUFFER    = $10000

; Structures

Structure LVBKIMAGE
   ulFlags.l
   hbm.l
   pszImage.l
   cchImageMax.l
   xOffsetPercent.l
   yOffsetPercent.l
 EndStructure
 
Global _lvBkImage.LVBKIMAGE                                                                                                         ; 

Procedure ListViewSetBackgroundImage(iGadget.i, handleImage.i)
  With lvbki.LVBKIMAGE
    \ulFlags        = #LVBKIF_TYPE_WATERMARK
    \hbm            = handleImage.i
    \yOffsetPercent = 10
    \xOffsetPercent = 10
  EndWith
  SendMessage_(iGadget.i, #LVM_SETBKIMAGE,  0,  lvbki)
  SendMessage_(iGadget.i, #LVM_SETTEXTBKCOLOR,  0,  #CLR_NONE)
  SendMessage_(iGadget.i, #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_DOUBLEBUFFER, #LVS_EX_DOUBLEBUFFER)
EndProcedure
Amateur Radio, D-STAR/VK3HAF
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Re: Background image in listicon, how to set 0, 0 pos?

Post by ebs »

How about setting the LVBKIMAGE structure members xOffsetPercent and yOffsetPercent to zero?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Background image in listicon, how to set 0, 0 pos?

Post by RASHAD »

Hi Fang
Nice to see you rolling around :)
Forget about xOffsetPercent & yOffsetPercent

Code: Select all

#LVBKIF_SOURCE_NONE = 0
#LVBKIF_SOURCE_HBITMAP = 1
#LVBKIF_SOURCE_URL = 2
#LVBKIF_SOURCE_MASK = 3
#LVBKIF_STYLE_NORMAL = 0
#LVBKIF_STYLE_TILE = $10
#LVBKIF_STYLE_MASK = $10
#LVBKIF_TYPE_WATERMARK = $10000000

Structure LVBKIMAGE Align #PB_Structure_AlignC
  ulFlags.l
  hbm.i
  pszImage.i
  cchImageMax.l
  xOffsetPercent.l
  yOffsetPercent.l
EndStructure

LoadFont(1, "Comic Sans Ms",10)

If OpenWindow(0, 100, 100, 640, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 0, 0, 640, 600, "", 0,#PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect )
  SetGadgetFont(0, FontID(1))
  AddGadgetColumn(0, 0, "COL 1", 213)
  AddGadgetColumn(0, 1, "COL 2", 213)
  AddGadgetColumn(0, 2, "COL 3", 213)
  For i = 1 To 19
    AddGadgetItem(0, -1, "1" + Chr(10) + "2" + Chr(10) + "3")
    AddGadgetItem(0, -1, "4" + Chr(10) + "5" + Chr(10) + "6")
    AddGadgetItem(0, -1, "7" + Chr(10) + "8" + Chr(10) + "9")
  Next

  lbk.LVBKIMAGE
  lbk\ulFlags = #LVBKIF_STYLE_NORMAL | #LVBKIF_SOURCE_URL | #LVBKIF_STYLE_TILE 
  lbk\pszImage = @"g:\mmedia\pictures\Image17.bmp"
  SendMessage_(GadgetID(0), #LVM_SETBKIMAGE, 0, @lbk)
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
EndIf
Edit : Bug fixed
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

ebs wrote:How about setting the LVBKIMAGE structure members xOffsetPercent and yOffsetPercent to zero?
Hi ebs. I tried that before posting, no difference.
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

Hi Fang
Hello sir!! Nice to 'hear' from you!
Nice to see you rolling around :)
Heeeeeeeeeeeeeeeeeeey!!! Is that a reference to my weight???
Forget about xOffsetPercent & yOffsetPercent
Yes sir!

Ps, could you modify your code to use this please instead of url? I pass the image id to the code and it works except for the huge offset of course:):)

Code: Select all

\hbm            = handleImage.i
I am loading the image from a packed file into memory and then setting it this way.

By the way, the double buffering helped avoid display 'tearing' when grid lines were on or long operations were taking place.

Code: Select all

SendMessage_(iGadget.i, #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_DOUBLEBUFFER, #LVS_EX_DOUBLEBUFFER)
Amateur Radio, D-STAR/VK3HAF
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Background image in listicon, how to set 0, 0 pos?

Post by RASHAD »

Hi Fang
Unfortunately there is a problem when using lbk\hbm(The image handle) and #PB_ListIcon_FullRowSelect flag
But it is OK now
Just added your suggestion and that mean we have now a serious contender with Windows API
I have to study more :)
Have fun Fang

Code: Select all

#LVBKIF_SOURCE_NONE = 0
#LVBKIF_SOURCE_HBITMAP = 1
#LVBKIF_SOURCE_URL = 2
#LVBKIF_SOURCE_MASK = 3
#LVBKIF_STYLE_NORMAL = 0
#LVBKIF_STYLE_TILE = $10
#LVBKIF_STYLE_MASK = $10
#LVBKIF_TYPE_WATERMARK = $10000000

Structure LVBKIMAGE Align #PB_Structure_AlignC
  ulFlags.l
  hbm.i
  pszImage.i
  cchImageMax.l
  xOffsetPercent.l
  yOffsetPercent.l
EndStructure

Global lbk.LVBKIMAGE

Procedure liCB()
  lbk\hbm = LoadImage(0,"g:\mmedia\pictures\Image17.bmp")
  SendMessage_(GadgetID(0), #LVM_SETBKIMAGE, 0, @lbk)
EndProcedure 

LoadFont(1, "Comic Sans Ms",12)

If OpenWindow(0, 100, 100, 640, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 0, 0, 640, 600, "", 0,#PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect )
  SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_DOUBLEBUFFER, #LVS_EX_DOUBLEBUFFER)
  
  SetGadgetFont(0, FontID(1))
  AddGadgetColumn(0, 0, "COL 1", 213)
  AddGadgetColumn(0, 1, "COL 2", 213)
  AddGadgetColumn(0, 2, "COL 3", 213)
  For i = 1 To 19
    AddGadgetItem(0, -1, "1" + Chr(10) + "2" + Chr(10) + "3")
    AddGadgetItem(0, -1, "4" + Chr(10) + "5" + Chr(10) + "6")
    AddGadgetItem(0, -1, "7" + Chr(10) + "8" + Chr(10) + "9")
  Next
  
  OleInitialize_(0)
  lbk.LVBKIMAGE
  lbk\ulFlags =   #LVBKIF_STYLE_TILE | #LVBKIF_SOURCE_HBITMAP
  lbk\hbm = LoadImage(0,"g:\mmedia\pictures\Image17.bmp")
  SendMessage_(GadgetID(0), #LVM_SETBKIMAGE, 0, @lbk)
  BindGadgetEvent(0,@liCB()) 
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug GetGadgetState(0)

      EndSelect
  EndSelect
Until Quit = 1
OleUninitialize_()
EndIf
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

I don't understand your code RASHAD, but that's normal.

1 Why are you loading the image twice???

2 Why are you still loading it from disk? I need to load my image by handle as it's coming from a pack file (As in my first post).

A very stoopid question would be, Doesn't the ListIconGadget pass events back any more without that binding? Or does something else happen?

My first version passes events back quite happily.
Amateur Radio, D-STAR/VK3HAF
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Background image in listicon, how to set 0, 0 pos?

Post by RASHAD »

Hi Fang
There is a problem when using lbk\hbm(The image handle) and #PB_ListIcon_FullRowSelect flag
The Gadget should be refreshed after each event

Code: Select all

#LVBKIF_SOURCE_NONE = 0
#LVBKIF_SOURCE_HBITMAP = 1
#LVBKIF_SOURCE_URL = 2
#LVBKIF_SOURCE_MASK = 3
#LVBKIF_STYLE_NORMAL = 0
#LVBKIF_STYLE_TILE = $10
#LVBKIF_STYLE_MASK = $10
#LVBKIF_TYPE_WATERMARK = $10000000

Structure LVBKIMAGE Align #PB_Structure_AlignC
  ulFlags.l
  hbm.i
  pszImage.i
  cchImageMax.l
  xOffsetPercent.l
  yOffsetPercent.l
EndStructure

LoadFont(1, "Comic Sans Ms",12)
handleImage.i = CatchImage(0,?background)

If OpenWindow(0, 100, 100, 640, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 0, 0, 640, 600, "COL 0",100,#PB_ListIcon_GridLines |#PB_ListIcon_FullRowSelect  )
  SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_DOUBLEBUFFER , #LVS_EX_DOUBLEBUFFER )
 
  SetGadgetFont(0, FontID(1))
  AddGadgetColumn(0, 1, "COL 1", 213)
  AddGadgetColumn(0, 2, "COL 2", 213)
  AddGadgetColumn(0, 3, "COL 3", 213)
  For i = 1 To 19
    AddGadgetItem(0, -1, "1" + Chr(10) + "2" + Chr(10) + "3")
    AddGadgetItem(0, -1, "4" + Chr(10) + "5" + Chr(10) + "6")
    AddGadgetItem(0, -1, "7" + Chr(10) + "8" + Chr(10) + "9")
  Next
 
  OleInitialize_(0)
  lbk.LVBKIMAGE
  lbk\ulFlags =   #LVBKIF_STYLE_TILE | #LVBKIF_SOURCE_HBITMAP
  lbk\hbm = handleImage.i
  SendMessage_(GadgetID(0), #LVM_SETBKIMAGE, 0, @lbk)
  
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug GetGadgetState(0)          
          RedrawWindow_(GadgetID(0),#Null,#Null,#RDW_INVALIDATE|#RDW_UPDATENOW)

      EndSelect
  EndSelect
Until Quit = 1
OleUninitialize_()
EndIf

DataSection
  background:
  IncludeBinary "g:\mmedia\pictures\Image17.bmp"
EndDataSection 
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

Hi Fang
Hello sir Wizard!
There is a problem when using lbk\hbm(The image handle) and #PB_ListIcon_FullRowSelect flag
Strange. Does this happen all the time or only sometimes? I don't seem to have that problem here. I'm running the latest Windows 10, Slow Ring and that all seems fine

Got another round of updates over the last 3 days and MS broke lots of things but not that bit:):)
Anyway, thanks for the update, I will play today in between chasing my wife, daughter and kitten around the house:):)
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

All fixed. Then I fiddled with the runtime loaded image, used desktopscaledx/desktopscaledy on it to get it to streth to the current dpi and it worked great.

Thank you Sir Master Wizard RASHAD!

Code: Select all

  ScaledBackImageWidth.i      = DesktopScaledX(Image("list background")\Width)  + 13
  ScaledBackImageHeight.i     = DesktopScaledY(Image("list background")\Height)
  
  Image("list background")\ID = ResizeImage(Image("list background")\Image, ScaledBackImageWidth.i, ScaledBackImageHeight.i)
  
  ; Add a background image into the ListIconGadget
  
  ListViewSetBackgroundImage(GadgetID(#Gadget_Mooklogin_loginlist), Image("list background")\ID)

Code: Select all

; Set a background image in a ListIconGadget - RASHAD

That '13' there seems to be a mis-scaling of the original image and it fixes it.

OleInitialize_(0)

#LVBKIF_SOURCE_NONE     = 0
#LVBKIF_SOURCE_HBITMAP  = 1
#LVBKIF_SOURCE_URL      = 2
#LVBKIF_SOURCE_MASK     = 3
#LVBKIF_STYLE_NORMAL    = 0
#LVBKIF_STYLE_TILE      = $10
#LVBKIF_STYLE_MASK      = $10
#LVBKIF_TYPE_WATERMARK  = $10000000

Structure LVBKIMAGE Align #PB_Structure_AlignC
  ulFlags.l
  hbm.i
  pszImage.i
  cchImageMax.l
  xOffsetPercent.l
  yOffsetPercent.l
EndStructure

Procedure ListViewSetBackgroundImage(iGadget.i, handleImage.i)
  
  lbk.LVBKIMAGE
  lbk\ulFlags   =   #LVBKIF_STYLE_TILE | #LVBKIF_SOURCE_HBITMAP
  lbk\hbm       = handleImage.i
  
  SendMessage_(iGadget.i, #LVM_SETBKIMAGE, 0, @lbk)
  SendMessage_(iGadget.i, #LVM_SETTEXTBKCOLOR,  0,  #CLR_NONE)
  SendMessage_(iGadget.i, #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_DOUBLEBUFFER, #LVS_EX_DOUBLEBUFFER)
  
EndProcedure

OleUninitialize_()
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

Crap, spoke too soon. Even with your refresh there for that gadget, it still does bad things (Shudder), okay very little notieable.

It's worse if I drag the window partly offscreen, it really messes it up so I added the refresh tot he windowmove event for that window as well but it only kicks in when you release the mouse.
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Background image in listicon, how to set 0, 0 pos?

Post by Fangbeast »

RASHAD, looks like I had the refresh in the wrong spot, it seems to work okay now with very minimal problems. I am happy with that.
Amateur Radio, D-STAR/VK3HAF
Post Reply