Solved

Changing style of font displayed in static text control box

Posted on 2004-05-02
11
878 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
Technology Partners: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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