Difficulty:
Very Easy
Cost:
Free
Average rating:
If you have new font and you need to make it available in every document processing softwares, you just need to copy font files into Windows font directory and you are done. Windows Explorer will manage font registration and housekeeping for you. If you need to know what is going on behind the scened or you need to know how to install/uninstall font programmatically through Delphi code, this short tutorial will explain it. 
Step 1:

To add a font resource, Windows Application Programming Interface (API) provides a developer with AddFontResource() function. This function expects font filename to be added. Following code snippet, add Arial font stored in file arial.ttf.

AddFontResource('c:\my custom fonts\arial.ttf'); 

Step 2:

Calling AddFontResource() is half of the process. To be able to notify any applications that a new font is installed, you need to broadcast WM_FONTCHANGE message to any applications.

SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0); 

Font installation is now complete. 

 

Step 3:

To remove any installed font, Windows API gives you RemoveFontResource(). Similar to AddFontResource(), this function also expects font filename to uninstall.

RemoveFontResource('c:\my custom fonts\arial.ttf');  

To notify any applications that a font has been uninstalled, you repeat StepTwo above after calling RemoveFontResource().

Zamrony P Juhara's picture
About this Author:
Zamrony P Juhara is a Delphi programmer from Indonesia currently living in Surabaya. He is very interested in DirectX programming topics. Currently, he maintains his own website, http://juhara.com, where he posts his DirectX programming articles.
View more information and all guides by Zamrony P Juhara