Page 1 of 1
WinXP Font Installation Help Needed
Posted: Tue Sep 12, 2006 3:11 am
by TerryHough
Help, I'm lost trying to automatically install fonts to WinXP.
It is easy enough to copy the fonts in to the proper directory using my installation routine. For Win98SE, all that was needed was a reboot for the fonts to be installed.
On WinXP, the fonts don't become active until they are "installed" using the Fonts dialog. (at least, I can't get them installed automatically.)
Can anyone give me a clue how to do this automatically? Either using a PB program or some command I am missing in an InnoSetup process?
TIA,
Terry
Posted: Tue Sep 12, 2006 3:37 am
by netmaestro
http://windowssdk.msdn.microsoft.com/en ... 33960.aspx
From what I can gather reading this, you would drop the .ttf file in the %windows%/fonts folder and then call AddFontResource and do the SendMessage_(), which should install it permanently and make it immediately available to all currently running programs. You'd want to avoid AddFontResourceEx as it seems to be tailored to installing fonts as private to an application.
Hm. Further reading under AddFontResource indicates that it won't be permanent until you put the font info in the registry. I have no idea where.
Posted: Tue Sep 12, 2006 3:38 pm
by netmaestro
OK, a bit of further research and testing produced a working procedure to accomplish the task. I downloaded a free ttf font called "Trashed" and tested it with the procedure. It was immediately available to programs system-wide, and remained persistent after a reboot. So - success. (I hope

)
Code: Select all
Procedure.l WriteRegKey(OpenKey.l, SubKey$, KeySet$, KeyValue$)
hKey.l = 0
If RegCreateKey_(OpenKey, SubKey$, @hKey) = 0
Result = 1
Datasize.l = Len(KeyValue$)
If RegSetValueEx_(hKey, KeySet$, 0, #REG_SZ, @KeyValue$, Datasize) = 0
Result = 2
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn Result
EndProcedure
Procedure InstallFont(Fontname$,FontFilename$)
Protected Fontdir$,key$
If AddFontResource_(FontFilename$)
Fontdir$ = GetEnvironmentVariable("windir")+ "\Fonts\"
If CopyFile(FontFilename$,Fontdir$ + FontFilename$)
SendMessage_(#HWND_BROADCAST, #WM_FONTCHANGE, 0, 0)
Select OSVersion()
Case #PB_OS_Windows_95,#PB_OS_Windows_98,#PB_OS_Windows_ME
key$ = "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts"
Default
key$ = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
EndSelect
If WriteRegKey(#HKEY_LOCAL_MACHINE, key$, Fontname$, FontFilename$)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
Else
ProcedureReturn 0
EndIf
Else
ProcedureReturn 0
EndIf
EndProcedure
Debug InstallFont("TRASHED","Trashed.ttf")
Posted: Tue Sep 12, 2006 3:42 pm
by rsts
This forum is an amazing resource.
cheers
Posted: Tue Sep 12, 2006 4:17 pm
by TerryHough
Thanks netmaestro!
I will study a bit on that too and give it some testing.
Terry
Posted: Sun May 31, 2009 4:44 pm
by jayagopal
rsts wrote:This forum is an amazing resource.
cheers
HELL YA!
ya... netmaestro you rock!
Posted: Sun May 31, 2009 4:56 pm
by NoahPhense
Boyaa!
thx NM
- np
Posted: Mon Jun 01, 2009 12:49 pm
by jayagopal
netmaestro,
sorry to bother you sir. do you know what i can change in your code to make it work with Type1 fonts (*.pfm & *.pfb pairs)?
:roll: