Solved

Changing style of font displayed in static text control box

Posted on 2004-05-02
11
803 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
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 10974977
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 87
Can someone Identify This font 4 79
string initialization in java 11 103
Window placement 17 65
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now