function TkzFonts.LoadResourceFont(const AInstance: THandle; const AResID: Integer; const AResTyp: {$IFDEF UNICODE}PWideChar{$ELSE UNICODE}PAnsiChar{$ENDIF UNICODE} = {$IFDEF UNICODE}PWideChar{$ELSE UNICODE}PAnsiChar{$ENDIF UNICODE}(RT_RCDATA)): Boolean;
var
LRes: TResourceStream;
i, LCount: Integer;
LMyFont: TMyFont;
begin
Result := False;
{$IFNDEF WINDOWS}
Exit;
{$ENDIF WINDOWS}
if ResourceExists(AInstance, AResID, AResTyp) then
begin
LRes := TResourceStream.CreateFromID(AInstance, AResID, PChar(AResTyp));
try
LMyFont.Handle := AddFontMemResourceEx(LRes.Memory, LRes.Size, nil, @LCount);
if ((LMyFont.Handle <> INVALID_HANDLE_VALUE) and (LMyFont.Handle <> 0)) then
Result := GetFontName(LRes, LMyFont);
if Result then
begin
i := Length(FMyFonts);
SetLength(FMyFonts, i + 1);
FMyFonts[i] := LMyFont;
FCount := Length(FMyFonts);
if (Assigned(FOnFontEvent)) then
FOnFontEvent(Self, FMyFonts[i].FontName, FMyFonts[i].Handle);
end;
finally
LRes.Free;
end;
end;
end;
function TkzFonts.LoadResourceFont(const AInstance: THandle; const AResName: {$IFDEF UNICODE}WideString{$ELSE UNICODE}AnsiString{$ENDIF UNICODE}; const AResTyp: {$IFDEF UNICODE}PWideChar{$ELSE UNICODE}PAnsiChar{$ENDIF UNICODE} = {$IFDEF UNICODE}PWideChar{$ELSE UNICODE}PAnsiChar{$ENDIF UNICODE}(RT_RCDATA)): Boolean;
var
LRes: TResourceStream;
i, LCount: Integer;
LMyFont: TMyFont;
begin
Result := False;
{$IFNDEF WINDOWS}
Exit;
{$ENDIF WINDOWS}
if ResourceExists(AInstance, AResName, AResTyp) then
begin
LRes := TResourceStream.Create(AInstance, string(AResName), PChar(AResTyp));
try
LMyFont.Handle := AddFontMemResourceEx(LRes.Memory, LRes.Size, nil, @LCount);
if ((LMyFont.Handle <> INVALID_HANDLE_VALUE) and (LMyFont.Handle <> 0)) then
Result := GetFontName(LRes, LMyFont);
if Result then
begin
i := Length(FMyFonts);
SetLength(FMyFonts, i + 1);
FMyFonts[i] := LMyFont;
FCount := Length(FMyFonts);
if (Assigned(FOnFontEvent)) then
FOnFontEvent(Self, FMyFonts[i].FontName, FMyFonts[i].Handle);
end;
finally
LRes.Free;
end;
end;
end;