DelphiFAQ Home Search:

Putting a background image on a ListView (Delphi 7)

 

comments18 comments. Current rating: 4 stars (8 votes). Leave comments and/ or rate it.

Question:

I need to display a bitmap as a background picture in a TListView control and it seems not to work.
I send a message LVM_SETBKIMAGE with the handle to a TLVBkImage, but no success.

Answer:

The code is ok but you need to change the handling of the WM_ERASEBKGND message by either traditional subclassing or - more Delphi style - defining your own TMyListView derived from TListView as shown in the example. Then change the declaration of your listview control from TListView to TMyListView (both in your DFM and in your PAS file) and it will work.

Notes:

  1. I noticed that I had to provide a full path to the image file. Just the file name (even though it was located in the application directory) did not work.
  2. Benoît Thonnart, a reader of this page wrote me that after he added uses ComObj; to his (version of this) code, it worked.

You can download a complete demo project that will compile under Delphi 7 (and since it has the constant definitions integrated, also under Delphi 5 and Delphi 6).
TListviewBackgroundImage.zip(240 kB)

type
  TMyListView = class(TListView)
  protected
    procedure WndProc(var Message: TMessage);
      override;
  end;

procedure TMyListView.WndProc(var Message: TMessage);
begin
  if Message.Msg = WM_ERASEBKGND then
    DefaultHandler(Message)
  else
    inherited WndProc(Message);
end;

procedure TForm1.LVBGImage;
var
  BKimg : TLVBKIMAGE;
begin
  FillChar(BKimg, SizeOf(BKimg), 0);
  BKimg.ulFlags := LVBKIF_SOURCE_URL  or LVBKIF_STYLE_TILE;
  BKimg.pszImage := PChar('c:\windows\angler.bmp');
  BKimg.xOffsetPercent := 0;
  BKimg.yOffsetPercent := 0;
  CoInitialize(nil);
  SendMessage(ListView1.Handle, LVM_SETTEXTBKCOLOR, 0, integer(CLR_NONE));
  SendMessage(ListView1.Handle, LVM_SETBKIMAGE, 0, integer(@BKimg));
  CoUninitialize;
end;

Comments:

You are on page 1 of 2, other pages: [1] 2
2005-12-12, 16:48:02
anonymous from Brazil  
rating
Great idea!
2006-03-09, 09:00:46
Craig from United Kingdom  
rating
I'd been looking for this FOREVER :D.

But how can I get it to load from a TBitmap instead of a file? I tried LVBKIF_STYLE_HBITMAP and LVBKIF_STYLE_MASK and it won't work...
2007-07-07, 16:30:07
anonymous from Sweden  
rating
Thanks, but cannot get it to only show one image (instead of showing same image side by side of itself), anyone know how to fix? :)
2008-03-13, 21:35:14   (updated: 2008-03-13, 21:35:44)
from Indonesia  
how to insert the substiem in listview in delphi i have tried so many time but i can found until noW , would you like to help meIII
2008-12-23, 04:30:39
[hidden]  
rating
This doesn't work with Delphi2009 + Vista
2009-08-12, 11:35:09
anonymous from South Africa  
Hi, I need to display a .jpg image as a theme in delphi and i cant find any help online.
2012-06-18, 21:39:01
anonymous from Colombia  
One alleged victim would routinely throw away his underwear to hide [url= http://www.louisvui..net/]Louis Vuitton Bags[/url] the supposed abuse. Week two of the trial began with a final prosecution witness. The mother of Victim No. 9 took the [url= http://www.chanelou..et/]Chanel Purses[/url] stand Monday to detail her son’s cover-up of the alleged sordid acts he suffered at Sandusky’s hands. “I [url= http://www.guccibel..rg/]Hermes Belts[/url] always wondered why he never had any underwear in the laundry,” she testified. “He just told me he had an [url= http://www.beltsout...org/]Mens Belts[/url] accident and he threw them out.” Indeed, she testified that he started becoming “sick” more often after [url= http://www.topbelts..org/]Gucci Belts[/url] spending time with the ex-Penn State coach. Victim No. 9 supposedly slept over at the Sandusky residence more than 100 times.Victim No. 9 testified [url= http://www.louisvui..net/]Louis Vuitton Handbags[/url] last Thursday that he screamed during one episode of alleged abuse, hoping that [url= http://www.beltsonl..com/]Louis Vuitton Belts[/url] Sandusky’s wife, who he said was always upstairs, would hear. “I think the basement is soundproof,” he said [url= http://www.chanels-..om/]Chanel Handbags[/url] tearfully, noting that Sandusky’s wife Dottie never did come down.Lead defense attorney Joe Amendola has also [url= http://www.chanelba..om/]Chanel Handbag[/url] suggested previously that the accusers and the Attorney General’s office might be colluding. Lead prosecutor Joe [url= http://www.lvshopos..net/]Louis Vuitton Purses[/url] McGettigan has often queried the alleged victims while on the stand: “Have I ever, ever, ever told you what to say?” which they’ve answered with resounding denials. But it could be a larger issue for Kline and the other subpoenaed attorneys to defend themselves against a [url= http://www.louisvui..com/]Louis Vuitton Purse[/url]
charge of violating the gag order issued by Judge Cleland, which bars any representative from either side from discussing the case with the media.


2012-09-14, 03:43:39
anonymous from Korea (R)  
[spammer 61.105.174.6]
2012-10-19, 11:18:48
 
rating
Payday Loans otmnzd get been administering US persons <a href=' http://ukpaydayloanstl.co.uk/ '>payday Advance uk</a> 0563 with hurried, easy payday loans representing elds, and we've lastly trumped-up our method! So instantly you extremely buoy delight in second agreements on prompt notes go forward, each finished upon <a href=' http://uspaydayloanstl.com/ '>quick payday loans</a> 5623 the cyberspace, without whatever recognition evaluations. We've been excavation with River lendors representing the elapsed infrequent months, securing the boss interestingness percentages and secured <a href=' http://canadapayday..oanstp.ca/ '>cash advances</a> 7119 consent representing EACH River appliers. Unfortunatley, in this far-reaching thrift, when maximal nation's monetary aspects assume't accomplish fresh, it moves us each. Thither's various judgments reason you want any additional notes, and at Payday Loans in Canada, we'system quick to accommodate the bridgework loans that Rivers desire. Contrivances amount up, brakes, automobile destroys, polyclinic pecker, furlough shopping. Any the impetus, we'system hither to support you entertain near between paydates. Try our payday loan servicing nowadays and you won't be discomfited. In near occasions, we buoy satisfy the notes you want, depositied the IDENTICAL time, at times inside an generation!
2012-10-21, 03:36:25
 
rating
vorlar <a href=' http://canadapayday..oanstr.ca/ '>pay day loans</a> 8]]] <a href=' http://uspaydayloansti.com/ '>pay day loan</a> 0930 <a href=' http://ukpaydayloansti.co.uk/ '>short term loan</a> 4658 <a href=' http://paydayloansnsa.com/ '>payday loans</a> >:-OOO <a href=' http://paydayloanso..inete.com/ '>cash advance</a> 3899
2012-11-12, 05:04:05
coach001 from United States  
2013-01-26, 19:02:16
anonymous from China  
Sennheiser (Sennheiser)<a href=' http://www.64gbusbm../'>64gb usb memory sticks</a> from the German brand is the most prestigious in the field of high-fidelity <a href=' http://www.quicken2..gt;quicken 2013</a>headphones enthusiasts almost<a href=' http://www.drdreear..fo/'>dr dre earphones</a> everyone knows, <a href=' http://www.quicken2..gt;quicken 2013 software</a>the history of over 50 years. <a href=' http://www.beatsstu..'>beats studio headphones</a>Founded in 1945,<a href=' http://www.turbotax..lt;/a>" target=_blank > http://www.turbotax..</a> recognized worldwide as the leading professional<a href=' http://www.beatswir..'>cheap beats wireless headphones</a> microphone and headphone manufacturer Sennheiser. <a href=' http://www.turbotax..t;turbotax 2012 download</a>Sennheiser continue to lead the trend of new audio technology,<a href=' http://www.beatsbyd..'>cheap beats by dre studio</a> research and development center in Hannover, <a href=' http://www.quickend..gt;quicken download</a>Germany. It is also the industry-recognized radio, <a href=' http://www.beatsbyd..'>cheap beats by dre solo</a>infrared sound transmission technology, <a href=' http://www.turbotax..scultation headphones,<a href=' http://www.beatsbyd..'>beats by dre tour</a> aviation call headphones, multimedia communication, a pioneer in the call center headsets and headphones.
2013-01-26, 19:03:57
anonymous from China  
2013-02-08, 02:35:37
 
rating
tombbtqk <a href=' http://paydayloansvba.co.uk/ '>payday cash</a> :-O <a href=' http://paydayloansvba.com/ '>payday advance</a> %-[[[ <a href=' http://paydayloansvba.ca/ '>cash advances</a> cgZGkK
2013-02-26, 21:55:29
anonymous  
You are on page 1 of 2, other pages: [1] 2

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: