Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

tfilelistbox displaying files with specific icons of the file..

Posted on 2003-10-23
2
Medium Priority
?
315 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 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

886 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