Question and Answer Database FAQ2309C.txt How do I add a TrueType font to Windows 95 in code? Category :VCL Platform :All Product :C++Builder 3.x Question: How do I add a TrueType font to Windows 95 in code? Answer: 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: // In the header file use: // #include// and // TRegistry *reg; NOTE: The WINGDING font is an example. void __fastcall TForm1::Button1Click(TObject *Sender) { bool b = false; b = CopyFile("C:\\Download\\WingDing.TTF","C:\\WINDOWS\\FONTS\\WingDing.TTF",b); reg = new TRegistry; reg->RootKey = HKEY_LOCAL_MACHINE; reg->LazyWrite = false; reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Fonts", b); reg->WriteString("WINGDING(TrueType)","WingDing.TTF"); reg->CloseKey(); reg->Free(); AddFontResource("C:\\Windows\\Fonts\\WingDing.TTF"); SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); RemoveFontResource("C:\\Windows\\Fonts\\WingDing.TTF"); SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); } 7/2/98 10:32:32 AM
Last Modified: 01-SEP-99