Embed font in an application
-
- Enthusiast
- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
Embed font in an application
Hello!
I have some applications which install special font files to C:\Windows\Fonts. It's the only thing that keeps me from making these applications run form a USB stick. Does anyone know if it is possible to "embed" or cheat the applications so that they load the fonts either from the current directory, or from somewhere in the exe?
Thanks in advance!
I have some applications which install special font files to C:\Windows\Fonts. It's the only thing that keeps me from making these applications run form a USB stick. Does anyone know if it is possible to "embed" or cheat the applications so that they load the fonts either from the current directory, or from somewhere in the exe?
Thanks in advance!
Code: Select all
Procedure AddFont(FontFileName.s)
AddFontResource_(FontFileName.s)
SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE, #NUL, #NUL)
EndProcedure
Procedure RemoveFont(FontFileName.s)
RemoveFontResource_(FontFileName.s)
EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- PureBasic Expert
- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Load from DataSection:
Load From executable directory:
Code: Select all
OpenLibrary(0,"gdi32.dll")
fontid=CallFunction(0,"AddFontMemResourceEx",?font,?end_font-?font,0,@"1")
CloseLibrary(0)
LoadFont(0,"anorexia",12)
DataSection
font:
IncludeBinary "anorexia.fon"
end_font:
EndDataSection
Code: Select all
OpenLibrary(0,"gdi32.dll")
AddFontResource_(GetCurrentDirectory()+"anorexia.fon")
SendMessage_(#HWND_BROADCAST, #WM_FONTCHANGE, 0, 0)
CloseLibrary(0)
LoadFont(0,"anorexia",12)
-
- Enthusiast
- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
-
- Enthusiast
- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
I'm still puzzled. Can you give me sample code showing what you are telling me?maw wrote:You already have the answer above. Use one of Num3's solutions, insert a RunProgram() to start the application and you're done.
So is it possible to make a "launcher" that opens up a 3rd party application, tells it to load the fonts locally and it works?
No, you simply load the font with the launcher which makes it available to all other programs. Just noticed on MSDN that AddFontMemResourceEx makes the font private so you have to stick with the AddFontResource.berryoxide wrote:So is it possible to make a "launcher" that opens up a 3rd party application, tells it to load the fonts locally and it works?
Code: Select all
AddFontResource_(fontname$)
SendMessage_(#HWND_BROADCAST, #WM_FONTCHANGE, 0, 0)
RunProgram(program$, "", "", #PB_Program_Wait)
RemoveFontResource_(fontname$)
SendMessage_(#HWND_BROADCAST, #WM_FONTCHANGE, 0, 0)
>> is it possible to make a "launcher" that opens up a 3rd party application,
>> tells it to load the fonts locally and it works?
>
> No, you simply load the font with the launcher which makes it available to
> all other programs
Well, the answer is yes, then.
His app loads the font, then launches the
other app, which can then use the new available font -- just like you said.
>> tells it to load the fonts locally and it works?
>
> No, you simply load the font with the launcher which makes it available to
> all other programs
Well, the answer is yes, then.

other app, which can then use the new available font -- just like you said.
Not to quibble over semantics but the answer is noPB wrote:>> is it possible to make a "launcher" that opens up a 3rd party application,
>> tells it to load the fonts locally and it works?
>
> No, you simply load the font with the launcher which makes it available to
> all other programs
Well, the answer is yes, then.His app loads the font, then launches the
other app, which can then use the new available font -- just like you said.

-
- Enthusiast
- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger