![]() |
| | #1 |
| Registered User Join Date: Jan 2003
Posts: 35
| All I want to do is wrap up my fonts (just Windows fonts) in their own class for a game. Piece of cake! Nothing but a bunch of fonts contained in a class, an Init routine which builds the different fonts, and a destructor that deletes them. Everything appears to be fine except that the wrapped-up "CreateFont" function doesn't seem to be working properly. The following is a public member function of the class: Code: HFONT GameFonts::MakeGameFont(int size, bool italic, char* style, int weight)
{
HFONT theFont = CreateFont(size, 0, 0, 0, weight,
italic, false, false, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
style);
return theFont;
}
Code: bool GameFonts::Init(HDC hdc)
{
bool success = true;
hfScoreFont = MakeGameFont(-20, true, "times new roman", FW_BOLD);
if(!hfScoreFont) success=false;
hfLevelFont = MakeGameFont(-15, false, "arial", FW_BOLD);
...
Well, the bottom line is this: Something is happening. If I go into the "CreateFont" function and put in the values for size, italic, etc (instead of using the values passed in) then it works, but for some reason the function's not taking the values I pass in! All the fonts are exactly the same! What's up with this? This same function worked perfectly when it was global. |
| fusikon is offline | |
| | #2 |
| Registered User Join Date: Jan 2003
Posts: 35
| Okay, sorry, update: The problem's not with the wrapped function, it's with selecting the fonts. For some reason all the fonts wind up being just one of the fonts, the Menu Items font. Why? Dunno why. I select all the fonts in the same way, like this: Code: SelectObject(hdc, (HFONT)gameFonts.hfMenuItFont); Code: SelectObject(hdc, (HFONT)gameFonts.hfMenuHdFont); Code: #ifndef GAME_FONTS_H
#define GAME_FONTS_H
#include <windows.h>
class GameFonts
{
public:
GameFonts(){ }
~GameFonts();
bool Init(HDC);
HFONT MakeGameFont(int, bool, char *, int=400 );
HDC * p_hdc;
HFONT hfScoreFont;
HFONT hfLevelFont;
HFONT hfAdvLevFont;
HFONT hfMenuHdFont;
HFONT hfMenuItFont;
HFONT hfTinyFont;
HFONT hfBodyFont;
HFONT hfFooterFont;
HFONT hfGetRdyFont;
HFONT hfGameOvFont;
HFONT hfOldFont;
};
#endif // GAME_FONTS_H
It seems as if the font is being selected only the first/second time, and then the SelectObject calls cease to have any effect. I really have no idea what's going on. I'm assuming that an HFONT is a set size and that assigning stuff to them doesn't change the size of the member data. But maybe I'm wrong. Last edited by fusikon; 02-09-2003 at 06:09 PM. |
| fusikon is offline | |
| | #3 |
| Registered User Join Date: Jan 2003
Posts: 35
| Yay! Got it! The solution was to pass in the address of the font class object, and then deference it: Code: SelectObject(hdc, gameFonts->hfScoreFont); Got another question, I'll put up the thread in a moment... |
| fusikon is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How properly inherit from template? | 6tr6tr | C++ Programming | 118 | 04-25-2008 04:30 AM |
| matrix class | shuo | C++ Programming | 2 | 07-13-2007 01:03 AM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| CEdit::OnChar() won't work for derived class! | LuckY | Windows Programming | 0 | 02-28-2003 01:01 AM |
| Abstract class problem | VanJay011379 | C++ Programming | 9 | 07-31-2002 01:30 PM |