Pobranie duzej ikony dysku (48x48)...

0

czesc

siedze i sziedze i szukam i nie znalazlem...
jak odczytac duza ikone dysku o podanej literze?

0

ExtractIconEx??

0

30 sekund z google + 2 minuty przeglądania wyników + 1 minuta odpalenie delphi, napisanie i test :/

var
  sfi: TSHFileInfo;
begin
  SHGetFileInfo('G:\', 0, sfi, SizeOf(TSHFileInfo), SHGFI_ICON or SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  DrawIcon(Canvas.Handle, 100, 100, sfi.hIcon);
  DestroyIcon(sfi.hIcon);
end;
0
Misiekd napisał(a)

30 sekund z google + 2 minuty przeglądania wyników + 1 minuta odpalenie delphi, napisanie i test :/

to to ja wiem... tylko ze to wciaz (no chyba ze na moim xp to inaczej dziala) jest ikona 32px...

byc moze ExtractIconEx rozwiazalo by sprawe, tylko ze ta funkcja wyciaga ikony tylko z plikow exe,dll itd...
zeby pobrac ikone dysku, musialbym sprawdzac jego typ (pendrive, cd, dysk twardy...) i ladowac odpowiednia ikone z shell32.dll czy tam innej biblioteki.
dodatkowo trzeba by tez sprawdzac czy do dysku nie zostala przypisana ikona w autorun.inf...
wiem ze da sie to zrobic w ten sposob ale szukalem czegos gotowego ;]

aha, juz nawet nie wspomne o specjalnych ikonach pochadzacych ze sterownika np czytnika kart.


dobra, znalazlem :-) :

uses ShellApi, Commctrl, ShlObj;

const
  SHIL_LARGE     = $00;  //The image size is normally 32x32 pixels. However, if the Use large icons option is selected from the Effects section of the Appearance tab in Display Properties, the image is 48x48 pixels.
  SHIL_SMALL     = $01;  //These images are the Shell standard small icon size of 16x16, but the size can be customized by the user.
  SHIL_EXTRALARGE= $02;  //These images are the Shell standard extra-large icon size. This is typically 48x48, but the size can be customized by the user.
  SHIL_SYSSMALL  = $03;  //These images are the size specified by GetSystemMetrics called with SM_CXSMICON and GetSystemMetrics called with SM_CYSMICON.
  SHIL_JUMBO     = $04;  //Windows Vista and later. The image is normally 256x256 pixels.
  IID_IImageList: TGUID= '{46EB5926-582E-4017-9FDF-E8998DAA0950}';

function GetImageListSH(SHIL_FLAG:Cardinal): HIMAGELIST;
type
  _SHGetImageList = function (iImageList: integer; const riid: TGUID; var ppv: Pointer): hResult; stdcall;
var
  Handle        : THandle;
  SHGetImageList: _SHGetImageList;
begin
  Result:= 0;
  Handle:= LoadLibrary('Shell32.dll');
  if Handle<> S_OK then
  try
    SHGetImageList:= GetProcAddress(Handle, PChar(727));
    if Assigned(SHGetImageList) and (Win32Platform = VER_PLATFORM_WIN32_NT) then
      SHGetImageList(SHIL_FLAG, IID_IImageList, Pointer(Result));
  finally
    FreeLibrary(Handle);
  end;
end;


Procedure GetIconFromFile(aFile:String; var aIcon : TIcon;SHIL_FLAG:Cardinal);
var
  aImgList    : HIMAGELIST;
  SFI         : TSHFileInfo;
Begin
    //Get the index of the imagelist
    SHGetFileInfo(PChar(aFile), FILE_ATTRIBUTE_NORMAL, SFI,
                 SizeOf( TSHFileInfo ), SHGFI_ICON or SHGFI_LARGEICON or SHGFI_SHELLICONSIZE or
                 SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_DISPLAYNAME );

    if not Assigned(aIcon) then
    aIcon:= TIcon.Create;
    //get the imagelist
    aImgList:= GetImageListSH(SHIL_FLAG);
    //extract the icon handle
    aIcon.Handle:= ImageList_GetIcon(aImgList, Pred(ImageList_GetImageCount(aImgList)), ILD_NORMAL);
End;

i uzycie:

var
 hicon :TIcon;
begin
    hicon:= TIcon.Create;
    try
     GetIconFromFile('C:\Tools\reflector\readme.htm',hicon,SHIL_EXTRALARGE);
     Image1.Picture.Icon.Assign(hIcon); //assign to timage
    finally
     hIcon.Free;
    end;
end;

zamiast pelnej nazwy pliku mozemy spokojnie podac samo "C:".
na viscie i nowszych mozemy dostac jeszcze wieksze ikony (256x256) podajac SHIL_JUMBO.

zrodlo: http://stackoverflow.com/questions/1703186/can-48x48-or-64x64-icons-be-obtained-from-the-vista-shell/1705373

pozdrawiam i dzieki za pomoc

0

już mi się nie chce sprawdzać, ale kod jest i podziękowania więc pewnie działa (kolejne 3min :p)
szukaj pod delphi + SHGetImageList oraz delphi + SHIL_EXTRALARGE

1 użytkowników online, w tym zalogowanych: 0, gości: 1