Re: TIcon

From
Yury Sinegubov ()
To
All ()
Date
2002-04-04T23:14:11Z
Area
RU.DELPHI
Сулейманов Тимур wrote:

> Подскажите как правильно создать объект TIcon имея hIcon,
> возвращаемый функцией ExtractIcon(...)

function CreateIcon(const FileName: string; Id: Integer): TIcon;
var
  S: array[0..255] of char;
  IconHandle: HIcon;
  Index: Word;
begin
  Result := TIcon.Create;
  try
    StrPLCopy(S, FileName, SizeOf(S) - 1);
    IconHandle := ExtractIcon(hInstance, S, Id);
    if IconHandle < 2 then begin
      Index := Id;
      IconHandle := ExtractAssociatedIcon(hInstance, S, Index);
    end;
    if IconHandle < 2 then begin
      if IconHandle = 1 then
        raise EResNotFound.Create(LoadStr(0))
      else begin
        Result.Free;
        Result := nil;
      end;
    end else Result.Handle := IconHandle;
  except
    Result.Free;
    raise;
  end;
end;

--
Yury.Sinegubov@consultant.com
--- Xnews/03.09.22
 * Origin: JSC Kontakt-Svyaz-Service Myski Kemerovo reg. Rus (2:5006/1@fidonet)