Solved

tfilelistbox displaying files with specific icons of the file..

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

860 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