Get Icon by File Type

Get Icon by File Type

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


void __fastcall TForm1::GetIcon(AnsiString FileName)
{
   SHFILEINFO sfi;
   SHGetFileInfo(
                  FileName.c_str(),
                  FILE_ATTRIBUTE_NORMAL,
                  &sfi,
                  sizeof(SHFILEINFO),
                  SHGFI_ICON
                );
   TIcon* picon = new TIcon();
   picon->Handle = sfi.hIcon;
   Image1->Canvas->Pen->Color = clWhite;
   Image1->Canvas->Brush->Color = clWhite;
   Image1->Canvas->Rectangle(0, 0, 32, 32 );
   Image1->Canvas->Draw( 0, 0, picon );
   DestroyIcon( sfi.hIcon );
   delete picon;
}

 

Dotblogs 的標籤: , ,