Solved

Changing style of font displayed in static text control box

Posted on 2004-05-02
11
852 Views
Last Modified: 2013-12-03
Hi experts, I've created a CDialog box and put a Static Text Control in it.

How do i change the font text to bold, the type of fonts and the font size for the text displayed in the control box?
Thanks.
0
Comment
Question by:pcssecure
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 3

Expert Comment

by:kklai72
ID: 10974864
try this, I got a button, when it is pressed, it changed the font of the static text (with ID IDC_TEXT) to bold type

void CTransparentDlg::OnButton1()
{
      // TODO: Add your control notification handler code here
      CWnd *pWnd;

      pWnd=this->GetDlgItem(IDC_TEXT);
      if (pWnd!=NULL) {
            LOGFONT lf;
            CFont *pOldFont;
            CFont *pNewFont;


            pOldFont=pWnd->GetFont();
            pOldFont->GetLogFont(&lf);
            lf.lfWeight=FW_BOLD;

            pNewFont=new CFont;
            pNewFont->CreateFontIndirect(&lf);
            
            pWnd->SetFont(pNewFont);
            delete pNewFont;

            pWnd->SetFont(pOldFont,FALSE);
      }
}
0
 
LVL 7

Assisted Solution

by:vijay_visana
vijay_visana earned 250 total points
ID: 10974934
     CStatic * pMySt = (CStatic *)GetDlgItem(IDC_STATIC);
      ASSERT(pMySt);
      CFont * pMyFont = pMySt->GetFont();
      LOGFONT LogFont;
      pMyFont->GetLogFont (&LogFont);
      LogFont.lfWeight = FW_BOLD;
      CFont newFont;
      newFont.CreateFontIndirect (&LogFont);
      pMySt->SetFont (&newFont);
0
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10974944
see the LOGFONT stucture
I have just change the Weight field but you can manipulate other fields to get desired font for your control.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:AlexFM
ID: 10974977
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 250 total points
ID: 10975301
A small change in VV's code :)

make this object as class member
in the header of the class put
CFont m_newFont;



    CStatic * pMySt = (CStatic *)GetDlgItem(IDC_STATIC);
     ASSERT(pMySt);
     CFont * pMyFont = pMySt->GetFont();
     LOGFONT LogFont;
     pMyFont->GetLogFont (&LogFont);
     LogFont.lfWeight = FW_BOLD;

     m_newFont.CreateFontIndirect (&LogFont);
     pMySt->SetFont (&m_newFont);

Rosh :)
0
 

Author Comment

by:pcssecure
ID: 10975483
hi vijay, i've successfully changed the text to bold but i can't seems to change the font size.
I tried to change the font size using the following statement, but the size is still the same.

logFont.lfHeight = -MulDiv(20, dc->GetDeviceCaps(LOGPIXELSY), 72);  

Pls advice.
Thks!
0
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10975814
In my code it is working fine.
do the following

HDC hdc = GetDC()->m_hDC ;
ASSERT(hdc);
int PointSize = 20;
int nHight = -MulDiv(PointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
//check nHight here in my pc it is -27
LogFont.lfHeight = nHight ;

0
 
LVL 14

Expert Comment

by:wayside
ID: 10976845
Are you trying to change one specific static text item, or all of the text in the dialog to the same font?

If you want to change all of them, you can change the font, size, and weight by setting a dialog property. For VC++.Net, right-mouse on the dialog title bar in the resource editor, select properties. In the properties window is a Font section that lets you change the font attributes.

I think there is someething equivalent in VC++6.0.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 117
Font: I need Lato on my Mac 10 460
abstract class with all non abstract mentods 6 84
make top menus bigger font 3 91
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question