Win2k don't like my coding...
-
I'm trying to change the font in the OnDraw function in a view: if (m_fontLarge == NULL) m_fontLarge->CreatePointFont (10 * (m_nLeftWidth-2), "Tahoma", pDC); CFont *old_font = pDC->SelectObject (m_fontLarge); and win2k just tells me that it won't allow this to happen and shuts down the application... and the same thing happens when I try setting a new brush... Any ideas of why? Andreas Philipson
-
I'm trying to change the font in the OnDraw function in a view: if (m_fontLarge == NULL) m_fontLarge->CreatePointFont (10 * (m_nLeftWidth-2), "Tahoma", pDC); CFont *old_font = pDC->SelectObject (m_fontLarge); and win2k just tells me that it won't allow this to happen and shuts down the application... and the same thing happens when I try setting a new brush... Any ideas of why? Andreas Philipson
You need to use "new" to allocate the font object before calling CreatePointFont. Ie... if (m_fontLarge == NULL) { m_fontLarge = new CFont; bla.bla.bla. }
-
I'm trying to change the font in the OnDraw function in a view: if (m_fontLarge == NULL) m_fontLarge->CreatePointFont (10 * (m_nLeftWidth-2), "Tahoma", pDC); CFont *old_font = pDC->SelectObject (m_fontLarge); and win2k just tells me that it won't allow this to happen and shuts down the application... and the same thing happens when I try setting a new brush... Any ideas of why? Andreas Philipson
That's because you're only executing your font code if m_fontLarge is NULL, and the first thing you do is dereference the NULL pointer with m_fontLarge->CreatePointFont(), which is where your exception comes from. m_fontLarge is NULL, so any pointer dereference on it will likely crash. if m_fontLarge is a CFont* then you need to allocate storage for it with new, if it's just a CFont, then it should never be NULL.