Einzelnen Beitrag anzeigen

IceTube
(Gast)

n/a Beiträge
 
#18

Re: Programmsymbol aus ListBox in TImage laden?

  Alt 16. Jun 2008, 16:58
Aber so funktioniert es:

Delphi-Quellcode:
uses ShellApi;

function IconFromFile(const Filename: String; IconNr: Word): HICON;
var
  buffer: array[0..2*MAX_PATH]of Char;
begin
  StrPCopy(buffer, Filename);
  Result := ExtractAssociatedIcon(HInstance, buffer, IconNr);
end;

procedure TForm1.Button1Click(Sender: TObject);
var IconIndex : Integer;
    h : hIcon;
    S : String;
    Icon : TIcon;
    Bitmap : TBitmap;
    OpenDialog : TOpenDialog;
begin
     openDialog := TOpenDialog.Create(self);
     openDialog.InitialDir := GetCurrentDir;
     openDialog.Options := [ofFileMustExist];
     openDialog.Filter := 'Anwendungen|*.exe;*.com';
     openDialog.FilterIndex := 0;


  if openDialog.Execute then
   begin
     Icon := TIcon.Create;
     IconIndex := 0;
     S := OpenDialog.FileName;
     h := IconFromFile(OpenDialog.FileName,1);
     Icon.Handle := h;
     ImageList1.AddIcon (Icon);
   try
    ImageList1.GetIcon(0, Icon);
    Image1.Canvas.Draw(0, 0, Icon);
  finally
    FreeAndNil(Icon);
    OpenDialog.Free;

  end;
end;
lg
  Mit Zitat antworten Zitat