EvoTalk

02 十二月, 2008

Get Icon by File Type

Posted by: asd In: C++| Code Snippet| 程式設計 ()

根據檔案的副檔名,取得 icon 圖案

C++:
  1. // 傳入的 FileName 可為 ".doc" 、".pdf"、".rar" ....
  2. void __fastcall TForm1::GetIcon(AnsiString FileName)
  3. {
  4.    SHFILEINFO sfi;
  5.    SHGetFileInfo(
  6.                   FileName.c_str(),
  7.                   FILE_ATTRIBUTE_NORMAL,
  8.                   &sfi,
  9.                   sizeof(SHFILEINFO),
  10.                   SHGFI_ICON
  11.                 );
  12.    TIcon* picon = new TIcon();
  13.    picon->Handle = sfi.hIcon;
  14.    Image1->Canvas->Pen->Color = clWhite;
  15.    Image1->Canvas->Brush->Color = clWhite;
  16.    Image1->Canvas->Rectangle( 0, 0, 32, 32 );
  17.    Image1->Canvas->Draw( 0, 0, picon );
  18.    DestroyIcon( sfi.hIcon );
  19.    delete picon;
  20. }

Tags: ,

Releated Posts



No Responses to "Get Icon by File Type"

Comment Form