Solved

tfilelistbox displaying files with specific icons of the file..

Posted on 2003-10-23
2
302 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

947 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

18 Experts available now in Live!

Get 1:1 Help Now