Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Adding TrueType fonts to windows in code.


How do I add a TrueType font to Windows 95 in code;   

    You should copy the file to the Windows\Fonts directory, then add an entry to the registry key: "'Software\Microsoft\Windows\CurrentVersion\Fonts". The entry will be the font name and the path (if different than the Windows\Fonts directory). Once the registry entry is written, you should make a call to the Windows API function AddFontRecource(), then broadcast a system-wide WM_FONTCHANGE message. Finally, you should make a call to the Windows API function RemoveFontRecource(), to remove the resource lock on the font file, and broadcast a second system-wide WM_FONTCHANGE message. Here is an example: uses Registry;

    procedure TForm .Button Click(Sender: TObject);
    var
      reg: TRegistry;
      b : bool;
    begin
      CopyFile('C:\DOWNLOAD\FP000 00.TTF',
               'C:\WINDOWS\FONTS\FP000 00.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)','FP000 00.TTF');
      reg.CloseKey;
      reg.free;
     {Add the font resource}
      AddFontResource('c:\windows\fonts\FP000 00.TTF');
      SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
     {Remove the resource lock}
      RemoveFontResource('c:\windows\fonts\FP000 00.TTF');
      SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
    end;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use