首页  编辑  

添加字体资源

Tags: /超级猛料/Font.字体/   Date Created:

AddFontResource(PChar('myfont.ttf'));

 SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);

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;

***************************

使用没有注册的字体资源:

procedure TForm1.FormCreate(Sender: TObject);

begin

 AddFontResource(PChar(ExtractFilePath(ParamStr(0) + 'YourFont.TTF')));

 SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

 RemoveFontResource(PChar(ExtractFilePath(ParamStr(0) + 'YourFont.TTF')));

 SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

end;