Solved

ListView background image

Posted on 2001-08-01
9
1,187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Expert Comment

by:BryGuy
ID: 6341632
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
ID: 6342141
I can't make it work on my winME, either...   :-(

Regards, Madshi.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6342658
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:New2Delphi
ID: 6343082
Listening...
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6343305
listening...for moment
0
 

Author Comment

by:ivan_llanas
ID: 6343959
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
ID: 8735252
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
ID: 8737388
0
 

Accepted Solution

by:
RotaredoM earned 0 total points
ID: 8822648
Finalized as recommended.

Question PAQed and 300 points refunded.

RotaredoM
CS Mod @ EE
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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