[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1755
  • Last Modified:

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 );

0
pipe
Asked:
pipe
1 Solution
 
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now