Sign in to follow this  
Habba

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this