Solved

ListView background image

Posted on 2001-08-01
9
1,160 Views
Last Modified: 2007-11-27
  This piece of code "should" set a background image to a TListView. Does anybody know why it does not do it?

const TheFile = 'c:\back.bmp';
var LVBkImg : TLVBkImage;
begin
   OleInitialize (NIL); // Required.

   LVBkImg.ulFlags  := LVBKIF_SOURCE_URL or LVBKIF_STYLE_TILE;
   LVBkImg.pszImage := PChar(TheFile);
   LVBkImg.cchImageMax := Length (TheFile);

   if not ListView_SetBkImage(ListView1.Handle, @LVBkImg) then Showmessage ('NO!');
   ListView_SetTextBkColor(ListView1.Handle, $FFFFFFFF);
end;

   The call to ListView_SetBkImage returns true (everything went ok), but the background image is not shown.

   More over, then next code "should" set the image from a HBITMAP intead of a filename:

var LVBkImg : TLVBkImage;
    b       : TBitmap;
begin
   OleInitialize (NIL); // Required.

   b := TBitmap.Create;
   b.LoadFromFile ('c:\back.bmp');
   LVBkImg.hbm := b.Handle;
   LVBkImg.ulFlags := LVBKIF_SOURCE_HBITMAP or LVBKIF_STYLE_TILE;

   if not ListView_SetBkImage(ListView1.Handle, @LVBkImg) then Showmessage ('NO!');
   ListView_SetTextBkColor(ListView1.Handle, $FFFFFFFF);
end;

   Here, the call to ListView_SetBkImage always returns false.

   They say this functions needs COMCTL32.DLL 4.70 or newer, but I tested it with 5.81 and nothing happened.

0
Comment
Question by:ivan_llanas
9 Comments
 

Expert Comment

by:BryGuy
Comment Utility
You might want to look at the source to TdfsExtListView from delphifreestuff.com.  There is a background property in it that *somtimes* works apparently - it's disabled by default because he couldn't get it to work all the time either, but it might help you.

Bryan Ashby
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
I can't make it work on my winME, either...   :-(

Regards, Madshi.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
This is from the Delphi 5 example "CustomDraw":

procedure TCustomDrawForm.TVCustomDraw(Sender: TCustomTreeView; const ARect: TRect;
  var DefaultDraw: Boolean);
begin
//This event should be used to draw any background colors or images.
//ARect represents the entire client area of the TreeView.
//Use the TreeView's canvas to do the drawing.
//Note that drawing a background bitmap is not really supported by CustomDraw,
//so scrolling can get messy. Best to subclass the TreeView and handle scrolling
//messages.
  with TV.Canvas do
  begin
    if None1.Checked then //no picture
    begin
      Brush.Color := BkgColorDialog.Color;
      Brush.Style := FBrushStyle;
      FillRect(ARect);
    end else
      if Tile1.Checked then //tile bitmap
      begin
        Brush.Bitmap := Image1.Picture.Bitmap;
          FillRect(ARect);
        end else //Stretch across the canvas.
            StretchDraw(ARect, Image1.Picture.Bitmap);
  end;
  DefaultDraw := FDefaultDraw;
  //setting DefaultDraw to false here prevents all calls to OnCustomDrawItem.
end;

It should be in your $(DELPHI)\Demos directory.

Stu
0
 

Expert Comment

by:New2Delphi
Comment Utility
Listening...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
listening...for moment
0
 

Author Comment

by:ivan_llanas
Comment Utility
I'm already using a working code that sets the background in a TListView, which uses some of the CustomDraw events and captures some internal TListView messages, a hard piece of code! but eventually have some problems in vsReport ViewStyle. I would like to use this because it's quite simple and I suppose it will be faster (this only if it works some day ;).
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

To be PAQ/Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
0
 

Accepted Solution

by:
RotaredoM earned 0 total points
Comment Utility
Finalized as recommended.

Question PAQed and 300 points refunded.

RotaredoM
CS Mod @ EE
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now