Fontes - usando sem instalar |
Top Previous Next |
|
I've worked with the fonts code and have some corrections for you to make it work with Delphi 2.0. I have not tried this on Delphi 3.0.
Information in an InstallShield article about installing fonts reveals that you do not need a FOT file in Win95 and WinNT environments. You only need the TTF file.
Resulting FormCreate code is as follows:
--------------------------------------------------------------------------------
var sAppDir, sFontRes: string; begin
{...other code...} sAppDir := extractfilepath(Application.ExeName);
sFontRes := sAppDir + 'MYFONT.TTF'; if FileExists( sFontRes ) then begin sFontRes := sFontRes + #0; if AddFontResource( @sFontRes[ 1 ] ) = 0 then bLoadedFont := false else begin bLoadedFont := true; SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0); end; end; {...}
end; {FormCreate}
-------------------------------------------------------------------------------- The resulting FormDestroy code is as follows: --------------------------------------------------------------------------------
var sFontRes, sAppDir: string; begin
{...other code...}
if bLoadedFont then begin sAppDir := extractfilepath(Application.ExeName); sFontRes := sAppDir + 'MYFONT.TTF' + #0; RemoveFontResource( @sFontRes[ 1 ] ); SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 ); end;
{...other code...}
end; {FormDestroy}
-------------------------------------------------------------------------------- To simplify these, I have created a simple function which can do both of these tasks. It returns a boolean which says whether or not the loading or unloading of the font was successful. --------------------------------------------------------------------------------
{1998-01-16 Font loading and unloading function.} function LoadFont(sFontFileName: string; bLoadIt: boolean): boolean; var sFont, sAppDir, sFontRes: string; begin result := TRUE;
if bLoadIt then begin {Load the font.} if FileExists( sFontFileName ) then begin sFontRes := sFontFileName + #0; if AddFontResource( @sFontRes[ 1 ] ) = 0 then result := FALSE else SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 ); end; end else begin {Unload the font.} sFontRes := sFontFileName + #0; result := RemoveFontResource( @sFontRes[1] ); SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 ); end; end; {LoadFont}
|