Solved

tfilelistbox displaying files with specific icons of the file..

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

19 Experts available now in Live!

Get 1:1 Help Now