Mega Code Archive

 
Categories / Delphi / System
 

How to add a true type font to the system

Title: How to add a true type font to the system Question: Add entries to the registry and inform the system... Answer: To install a font on the system you have to copy the font-file into 'Windows\Fonts' and add a key in the registry: 'Software\Microsoft\Windows\CurrentVersion\Fonts' This key points to the font-file. Afterwards the API function 'AddFontRecource' has to be executed. Finally the system has to be notified with a broadcast message. uses Registry; procedure TForm1.Button1Click(Sender: TObject); var hReg: TRegistry; hBool : bool; begin CopyFile('C:\DOWNLOAD\FP000100.TTF', 'C:\WINDOWS\FONTS\FP000100.TTF', hBool); hReg := TRegistry.Create; hReg.RootKey := HKEY_LOCAL_MACHINE; hReg.LazyWrite := false; hReg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Fonts', false); hReg.WriteString('TESTMICR (TrueType)','FP000100.TTF'); hReg.CloseKey; hReg.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;