# GDI and custom fonts

## Recommended Posts

I'd like to use an external font file (.ttf) with GDI-function 'DrawText'. The problem is that I don't know how to load the font from the file. It could perhaps work with 'AddFontResource'-function, but is it the best way to do it? It could interfere with other programs and I don't want that other programs could use my font too. In short: How to load font without having to send VM_FONTCHANGE message and how to keep my font private? Oh, and another question: Is it possible to add the font file in my resource file too? I'd like to hide it so that no one could alter or delete it. I'm using VC++ 6.

##### Share on other sites
If you want to make sure that only your program can use your font (so that it doesnt interfere with other processes) use AddFontResourceEx() with the FR_PRIVATE flag.

As for hiding the font, you can probably put the font in your resources, then read the data from your front in your resources and put that data into a temporary font file and then call AddFontResourceEx().

##### Share on other sites
Thanks for tip. I still have a slight problem: My compiler says that AddFontResourceEx() is "undeclared identifier". I have included windows.h and I have gdi32.lib linked to the project and they should be in correct locations. Am I missing something here?

I'm using WinXP, so it should work for me (MSDN says "Included in Windows 2000 and later).

##### Share on other sites
You need to tell the windows headers that it's ok that your code won't run on NT4 and earlier. put
#define _WIN32_WINNT 0x0500

before you include windows.h.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627745
• Total Posts
2978904

• 10
• 10
• 21
• 14
• 14