Link to home
Start Free TrialLog in
Avatar of xn12z9i
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->CreateFontIndirect( &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 ?
Avatar of cdesigner
cdesigner
Flag of Russian Federation image

try to make "LOGFONT lf; "
a global variable

I use LOGFONT scructure always before print.
ASKER CERTIFIED SOLUTION
Avatar of Nicolay_Ch
Nicolay_Ch

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial