WinXP Font Installation Help Needed

Windows specific forum
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

WinXP Font Installation Help Needed

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 :wink: )

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")
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

This forum is an amazing resource.

cheers
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Thanks netmaestro!

I will study a bit on that too and give it some testing.

Terry
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

rsts wrote:This forum is an amazing resource.

cheers
HELL YA!

ya... netmaestro you rock!
Repeat this sequence out loud:
*say hare krishna twice
*then say krishna twice
*then say hare twice
*then do the whole thing with rama instead of krishna
if you do this correctly, a representative will appear with further instructions
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Boyaa! 8)

thx NM

- np
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post 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:
Repeat this sequence out loud:
*say hare krishna twice
*then say krishna twice
*then say hare twice
*then do the whole thing with rama instead of krishna
if you do this correctly, a representative will appear with further instructions
Post Reply