I am trying to use fonts in my program without installing them on the
user's (target) computer as this requires a re-boot before the fonts are
available. I have done many of the steps but something is missing. Any
help would be appreciated. Thanks in advance for any help offered.
Bobby Clarke
Here are the steps I have taken:
Created file resource.rc containing two lines of text:
ABC1 RT_FONT C:\...\ABC01.ttf
ABC2 RT_FONT C:\...\ABC02.ttf
Used brcc32.exe in a batch file to compile to resource.res
In the Delphi program, I have
implementation
{$R *.dfm}
{$R resource.res}
procedure TFMain.FormCreate(Sender: TObject);
var
hFind : THandle;
begin
hFind := FindResource(Handle,'ABC1',RT_FONT); // returns zero
if hFind = 0 then
ShowMessage(' FindResource failed. Error: '+IntToStr(GetLastError))
else // untested as I never got this far
with TResourceStream.Create(hInstance,'ABC1',RT_FONT) do
try
SavetoFile(sAppDir+'ABC01.ttf');
AddFontResource( PChar(sAppDir+'ABC01.ttf'));
SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
finally
Free;
FreeResource(hFind) ;
end;
end;
Notes:
Result is that hFind is zero and GetLastError gives 1812 Resource Data
not found. I have tried replacing Handle with hInstance and
Application.Handle with the same result. Using an invalid Handle gives
1814 Resource Name not found.
The FindResource line was added as a diagnostic. Originally I went
straight to TResourceStream.Create but this produced an exception.
I am picking up the correct resource.res file as changing the name of
the actual file gives a compilation error.
[Non-text portions of this message have been removed]