Solved

tfilelistbox displaying files with specific icons of the file..

Posted on 2003-10-23
2
305 Views
Last Modified: 2012-05-04
Hi,

     Can you please help me with this. i have a tfilelistbox object and what i
     want is a complete code to display not only the files but also the specific
     icon. thanks.
0
Comment
Question by:therooster
  • 2
2 Comments
 
LVL 5

Expert Comment

by:snehanshu
ID: 9611675
TFileListBox has a property called ShowGlyphs. You can set it to true at design time or on formcreate.
...Snehanshu
0
 
LVL 5

Accepted Solution

by:
snehanshu earned 250 total points
ID: 9611823
ShowGlyphs perhaps shows old style icons. Here's code of a component I found on the net that does what you want:

unit janFileListBox;

{  author: Jan Verhoeven
   created: 18-Februari-2001
   email: jan1.verhoeven@wxs.nl
   url: http://jansfreeware.com/jfdelphi.htm

}

interface

uses
  Windows, Messages, ShellAPI,SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, FileCtrl,ImgList;

type
  TjanFileListBox = class(TFileListBox)
  private
    { Private declarations }
    ImageList   : TImageList;
  protected
    { Protected declarations }
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
  public
    { Public declarations }
    constructor create(AOwner:Tcomponent);override;
    destructor  destroy;override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('janBasic', [TjanFileListBox]);
end;

{ TjanFileListBox }


constructor TjanFileListBox.create(AOwner: Tcomponent);
begin
  inherited;
  Parent:=AOwner as TWinControl;
  Style:=lbOwnerDrawFixed;
  ImageList:=TImageList.Create(Self);
  ItemHeight:=18;
end;

destructor TjanFileListBox.destroy;
begin
  ImageList.free;
  inherited;

end;

procedure TjanFileListBox.DrawItem(Index: Integer; Rect: TRect;
  State: TOwnerDrawState);
var
  Icon  : TIcon;
  Glyph : TBitmap;
  Nr    : Word;
  fn:string;
begin
    ImageList.Clear;
    Canvas.FillRect(Rect);
    Nr:=0;
    Icon:=TIcon.Create;
    Glyph:=TBitmap.Create;
    Glyph.Width:=16;
    Glyph.Height:=16;
    if copy(FDirectory,length(FDirectory),1)='\' then
      fn:=FDirectory+Items.Strings[Index]
    else
      fn:=FDirectory+'\'+Items.Strings[Index];
    Icon.Handle:=ExtractAssociatedIcon(Application.Handle,PChar(fn),Nr);
    ImageList.AddIcon(Icon);
    if odSelected in State then ImageList.DrawingStyle:=dsSelected else ImageList.DrawingStyle:=dsNormal;
    ImageList.Draw(Canvas,Rect.Left + 2,Rect.Top + 1,0);
    Canvas.TextOut(Rect.Left + 20,Rect.Top + 1,Items.Strings[Index]);
    Glyph.Free;
    Icon.Free;
end;


end.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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