How to set font type and size using DrawText


Hello,
  Im using the following code to output text to the screen. However, I want to change the font to arial and make the size smaller. How can I go about doing this?

thanks,
  jer

CRect rect;
rect.top = 110;
rect.left = 0;
rect.bottom = 310;
rect.right = 300;

dc->SetTextColor( RGB( 255, 255, 255 ) );

dc->SetBkMode( TRANSPARENT );

dc->DrawText( "10:31pm", &rect, DT_CENTER );

pipeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

basantCommented:
BOOL CreateFontObject(int nOption,CFont* pFont)
{
      if(nOption == 1) // Verical Medium Font
            pFont->CreateFont(16,0,900,0,FW_BOLD,FALSE,FALSE,FALSE,
                         0,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                         DEFAULT_QUALITY,
                         VARIABLE_PITCH | FF_ROMAN,"Roman");
      if(nOption == 2) // Horizontal Medium Font
            pFont->CreateFont(16,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,
                         0,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                         DEFAULT_QUALITY,
                         VARIABLE_PITCH | FF_ROMAN,"Roman");
      if(nOption == 3) // Horizontal Small Font
            pFont->CreateFont(14,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,
                         0,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                         DEFAULT_QUALITY,
                         VARIABLE_PITCH | FF_ROMAN,"Roman");
      if(nOption == 4) // Horizontal Small Font
            pFont->CreateFont(14,0,0,0,FW_MEDIUM,FALSE,FALSE,FALSE,
                         0,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                         DEFAULT_QUALITY,
                         VARIABLE_PITCH | FF_ROMAN,"Roman");
return TRUE;
}


// The above code shows how to create new fonds . There example of different kind of fonts there

      CFont newFont;
      CreateFontObject(1,&newFont);
        CFond* pOldFont = dc->SelectObject( &newFont );
       // Now draw the text :
       dc->TextOut( .. );
....


// AfterFinishing.
      dc->SelectObject( pOldFont);
      newFont.DeleteObject();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chensuCommented:
CFont fnt;
fnt.CreatePointFont(120, _T("Arial"));

CFont *pOldFont = dc->SelectObject(&fnt);

dc->DrawText( "10:31pm", &rect, DT_CENTER );

dc->SelectObject(pOldFont);
0
pipeAuthor Commented:
thanks both!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.