en el proyecto simulo la llegada de las letras de las unidades y en otra cadena recibira el drivetype para identificarlos y agregar el icono correcto
en el combobox
(en imagelist1 tengo los 3 iconos de disco )
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList,shellapi, ExtCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ImageList1: TImageList;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ImageList2: TImageList;
procedure Button2Click(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
str:tstringlist;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//simulando lectura y dibujo de icono de discos logicos de conexion cliente server para filemanager
{ 0 = Unknown
1 = No Root Directory
2 = Removable Disk
3 = Local Disk
4 = Network Drive
5 = Compact Disc
6 = RAM Disk }
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
iconicof:ticon;
begin
//suponiendo que el server me manda los datos de letra de unidad y aparte lel drivetype de cada uno
//intento colocar el icono corecto en un combobox
combobox1.Clear;
str:=tstringlist.create;
iconicof:= TIcon.Create;
str.add( 'Removable Disk');
str.add( 'Local Disk');
str.add( 'Local Disk');
str.add( 'Removable Disk');
str.add( 'Compact Disc');
str.add( 'Compact Disc');
ComboBox1.Items.Add('A:\');
ComboBox1.Items.Add('C:\');
ComboBox1.Items.Add('F:\');
ComboBox1.Items.Add('G:\');
ComboBox1.Items.Add('H:\');
ComboBox1.Items.Add('I:\');
for i:=0 to str.Count -1 do begin
if str.strings[i] = 'Local Disk' then
imagelist1.GetIcon(0,iconicof);
if str.strings[i] = 'Removable Disk' then
imagelist1.GetIcon(1,iconicof);
if str.strings[i] = 'Compact Disc' then
imagelist1.GetIcon(2,iconicof);
imagelist2.addicon(iconicof);
end;
iconicof.Free;
str.Free;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
AnIcon : TIcon;
begin
AnIcon := TIcon.Create;
try
with Control as TComboBox do begin
form1.ImageList2.GetIcon (index,AnIcon);
//dibuja el icono
Canvas.Draw (Rect.Left,Rect.Top,AnIcon);
//dibuja el texto que precede al icono
Canvas.TextOut (Rect.Left + form1.ImageList2.Width,Rect.Top,Items[Index]);
end;
finally
AnIcon.Free;
end;
END;
end.