// Es wird ein eigenes TListView erstellt.

// Getestet mit D2010 unter Win7

// Variante 1:
//
geschachteltes Hintergrundbild

uses commctrl, activex; 
 
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 LVBack(lv: TCustomListView; bm: String); 
var 
  img: TLVBKIMAGE; 
begin 
  OleInitialize(nil); 
  zeromemory(@img, sizeof(img)); 
  lv.DoubleBuffered := true; 
  SendMessage(lv.Handle, LVM_SETTEXTBKCOLOR, 0, integer(CLR_NONE)); 
  img.ulFlags := LVBKIF_SOURCE_URL or LVBKIF_STYLE_TILE; 
  img.pszImage := PChar(bm); 
  SendMessage(lv.Handle, LVM_SETBKIMAGE, 0, integer(@img)); 
end; 
 
 
// Beispiel 

var 
 MLV: TMyListView;  

procedure TForm1.FormCreate(Sender: TObject); 
begin 
  MLV := TMyListView.Create(self); 
  MLV.Parent := self; 
  MLV.Left := 200; 
  MLV.Top := 100; 
  MLV.Height := 300; 
  LVBack(MLV, 'd:\Bilder\frau.bmp'); 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
  MLV.Free; 
end; 

-----------------------------------------------------

// Variante 2:
//
gestretchtes Hintergrundbild

uses commctrl; 
 
type 
  TMyListView = class(TListView) 
  protected 
    procedure CreateHandle; override; 
    procedure CreateParams(var Params: TCreateParams); override; 
    procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND; 
  public 
    Pic: TBitmap; 
  end; 
 
procedure TMyListView.CreateHandle; 
begin 
  inherited; 
  SendMessage(Handle, LVM_SETTEXTBKCOLOR, 0, CLR_NONE); 
end; 
 
procedure TMyListView.CreateParams(var Params: TCreateParams); 
begin 
  inherited; 
  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, Pic.Canvas.Handle, 0, 0, Pic.Width, 
    Pic.Height, SrcCopy); 
  Msg.Result := 1; 
end; 
 
 
// Beispiel 
 
var 
  MLV: TMyListView;  
  bmp: TBitmap; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  bmp := TBitmap.Create; 
  bmp.LoadFromFile('d:\Bilder\frau.bmp'); 
  MLV := TMyListView.Create(self); 
  MLV.Parent := self; 
  MLV.Pic := bmp; 
  MLV.Left := 200; 
  MLV.Top := 100; 
  MLV.Height := bmp.Height * 3; 
  MLV.Width := bmp.Width * 3; 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
  MLV.Free; 
  bmp.Free; 
end;

 


 

Zugriffe seit 6.9.2001 auf Delphi-Ecke