Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In order to set a watermark in the listview you need to use the <a href="http://msdn.microsoft.com/en-us/library/bb761155%28VS.85%29.aspx" rel="nofollow">LVM_SETBKIMAGE</a> message, and you need to override the TListView's default WM_ERASEBKGND message. The listview takes ownership of the bitmap handle, so you need to use TBitmap's <code>ReleaseHandle</code>, rather than just <code>Handle</code>.</p> <p>If you want it aligned to the top-left, instead of the bottom right like Explorer, use <code>LVBKIF_SOURCE_HBITMAP</code> instead of <code>LVBKIF_TYPE_WATERMARK</code> for the <code>ulFlags</code> value.</p> <pre><code>uses CommCtrl, ...; type TListView = class(ComCtrls.TListView) protected procedure WndProc(var Message: TMessage); override; end; TForm4 = class(TForm) ListView1: TListView; procedure FormCreate(Sender: TObject); end; procedure TListView.WndProc(var Message: TMessage); begin if Message.Msg = WM_ERASEBKGND then DefaultHandler(Message) else inherited WndProc(Message); end; procedure TForm4.FormCreate(Sender: TObject); var Img: TImage; BkImg: TLVBKImage; begin FillChar(BkImg, SizeOf(BkImg), 0); BkImg.ulFlags := LVBKIF_TYPE_WATERMARK; // Load image and take ownership of the bitmap handle Img := TImage.Create(nil); try Img.Picture.LoadFromFile('C:\Watermark.bmp'); BkImg.hbm := Img.Picture.Bitmap.ReleaseHandle; finally Img.Free; end; // Set the watermark SendMessage(ListView1.Handle, LVM_SETBKIMAGE, 0, LPARAM(@BkImg)); end; </code></pre> <p><strong>Stretched Watermark</strong></p> <p>The listview doesn't natively support stretching a bitmap across the entire background. To do so you need to do a StretchBlt in response to WM_ERASEBKGND yourself.</p> <pre><code>type TMyListView = class(TListView) protected procedure CreateHandle; override; procedure CreateParams(var Params: TCreateParams); override; procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND; public Watermark: TBitmap; end; procedure TMyListView.CreateHandle; begin inherited; // Set text background color to transparent SendMessage(Handle, LVM_SETTEXTBKCOLOR, 0, CLR_NONE); end; procedure TMyListView.CreateParams(var Params: TCreateParams); begin inherited; // Invalidate every time the listview is resized Params.Style := Params.Style or CS_HREDRAW or CS_VREDRAW; end; procedure TMyListView.WMEraseBkgnd(var Msg: TWMEraseBkgnd); begin StretchBlt(Msg.DC, 0, 0, Width, Height, Watermark.Canvas.Handle, 0, 0, Watermark.Width, Watermark.Height, SrcCopy); Msg.Result := 1; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload