xn12z9i
asked on
SelectObject( pFont ) returns NULL
I have defined a CFont* member in my CFormView class. The font is created as follows:
<snip>
LOGFONT lf;
lf.lfHeight = -100;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = (BYTE) 0;
lf.lfUnderline = (BYTE) 0;
lf.lfStrikeOut = (BYTE) 0;
lf.lfCharSet = (BYTE) ANSI_CHARSET;
lf.lfOutPrecision = (BYTE)OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = (BYTE) CLIP_DEFAULT_PRECIS;
lf.lfQuality = (BYTE) DEFAULT_QUALITY;
lf.lfPitchAndFamily = (BYTE) DEFAULT_PITCH|FF_DONTCARE;
strcpy( lf.lfFaceName, _T("Arial") );
m_pTextFont = new CFont;
ASSERT( m_pTextFont );
if( ! m_pTextFont->CreateFontInd irect( &lf ) )
TRACE0("error creating Arial font\n");
ASSERT_VALID( m_pTextFont );
</snip>
When I select the CFont* object into the device context in OnPrint(), pDC->SelectObject( m_pTextFont ) consistently returns NULL, and my font is not selected into the DC:
<snip>
if( pDC->IsPrinting() )
pDC->SetMapMode( MM_HIENGLISH );
CFont * pOldFont = pDC->SelectObject( m_pTextFont );
</snip>
Any ideas as to why this is happening ?
<snip>
LOGFONT lf;
lf.lfHeight = -100;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = (BYTE) 0;
lf.lfUnderline = (BYTE) 0;
lf.lfStrikeOut = (BYTE) 0;
lf.lfCharSet = (BYTE) ANSI_CHARSET;
lf.lfOutPrecision = (BYTE)OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = (BYTE) CLIP_DEFAULT_PRECIS;
lf.lfQuality = (BYTE) DEFAULT_QUALITY;
lf.lfPitchAndFamily = (BYTE) DEFAULT_PITCH|FF_DONTCARE;
strcpy( lf.lfFaceName, _T("Arial") );
m_pTextFont = new CFont;
ASSERT( m_pTextFont );
if( ! m_pTextFont->CreateFontInd
TRACE0("error creating Arial font\n");
ASSERT_VALID( m_pTextFont );
</snip>
When I select the CFont* object into the device context in OnPrint(), pDC->SelectObject( m_pTextFont ) consistently returns NULL, and my font is not selected into the DC:
<snip>
if( pDC->IsPrinting() )
pDC->SetMapMode( MM_HIENGLISH );
CFont * pOldFont = pDC->SelectObject( m_pTextFont );
</snip>
Any ideas as to why this is happening ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
a global variable
I use LOGFONT scructure always before print.