标签:ring broadcast nbsp win pos public cli creates procedure
uses Registry;
procedure TForm1.Button1Click(Sender: TObject);
var
reg: TRegistry;
b : bool;
begin
CopyFile(‘C:\DOWNLOAD\FP000100.TTF‘,
‘C:\WINDOWS\FONTS\FP000100.TTF‘, b);
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.LazyWrite := false;
reg.OpenKey(‘Software\Microsoft\Windows\CurrentVersion\Fonts‘,
false);
reg.WriteString(‘TESTMICR (TrueType)‘,‘FP000100.TTF‘);
reg.CloseKey;
reg.free;
{Add the font resource}
AddFontResource(‘c:\windows\fonts\FP000100.TTF‘);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
{Remove the resource lock}
RemoveFontResource(‘c:\windows\fonts\FP000100.TTF‘);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;
//////////////////////////////////
type
TForm1=class( TForm )
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
...
private
{ Private declarations }
bLoadedFont: boolean;
public
{ Public declarations }
end;
procedure TForm1.FormCreate(Sender: TObject);
var
sAppDir: string;
sFontRes: string;
begin
sAppDir := Application.ExeName;
sAppDir := copy( sAppDir, 1, rpos( ‘\‘, sAppDir ) );
sFontRes := sAppDir + ‘MYFONT.FOT‘;
if not FileExists( sFontRes ) then
begin
sFontRes := sFontRes + #0;
sFont := sAppDir + ‘MYFONT.TTF‘ + #0;
CreateScalableFontResource( 0, @sFontRes[ 1 ], @sFont[ 1 ], nil );
end;
sFontRes := sAppDir + ‘MYFONT.FOT‘;
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;
procedure TForm1.FormDestroy(Sender: TObject);
var
sFontRes: string;
begin
if bLoadedFont then
begin
sFontRes := sAppDir + ‘MYFONT.FOT‘ + #0;
RemoveFontResource( @sFontRes[ 1 ] );
SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
end;
end;
标签:ring broadcast nbsp win pos public cli creates procedure
原文地址:http://www.cnblogs.com/yzryc/p/6374330.html