Website Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • August 31, 2015, 01:47:44 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Static Text Control Font Size  (Read 11317 times)

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Static Text Control Font Size
« on: March 03, 2009, 02:28:22 AM »
Hi,

Can some one please tell me a easy way to make these to static text label controls in MFC, MS Visual Studio have a larger text font.

I would like.

IDC_Words to have a font size of 70.
IDC_Answer to have a font size of 50.

I have tried GetDlgItem(IDC_Word)->SetWindowTextW(); and IDC_Answer::FONTSIZE(50); but both do not work.

Thanks

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #1 on: March 03, 2009, 02:53:27 AM »
I believe you would have to create your own font object and load it into the control. All I can offer is WTL based code, but the MFC equivilent may not differ all that much.

Code: C++
  1. CFont font_fixedw_;
  2.  
  3. ...
  4.  
  5. if (CFont font = GetFont())
  6. {
  7.         CLogFont lf;           
  8.  
  9.         if (font.GetLogFont(&lf))
  10.         {
  11.                 lf.lfWidth = 6;
  12.                 lf.lfPitchAndFamily = FIXED_PITCH;
  13.                 lf.lfFaceName[0] = 0;
  14.                 font_fixedw_.CreateFontIndirect(&lf);
  15.         }
  16. }
  17.  
  18. CWindow wndControl = GetDlgItem(IDC_DESCRIPTION);
  19. wndControl.SetFont(font_fixedw_);

Hope it is of some help.

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #2 on: March 03, 2009, 03:49:51 AM »
Hi

If I change your code to this I only get one error, which I am not sure on how to fix.

Code: C++
  1. CFont font_fixedw_;
  2. .
  3. .
  4. .
  5. LOGFONT lf;
  6. lf.lfWidth = 6;
  7. lf.lfPitchAndFamily = FIXED_PITCH;
  8. lf.lfFaceName[0] = 0;
  9. font_fixedw_.CreateFontIndirect(&lf);
  10.        
  11. CWnd *wndControl = GetDlgItem(IDC_Word);
  12. wndControl.SetFont(font_fixedw_); //Error Error C2228: left of '.SetFont' must have class/struct/union 
  13.  
  14.  


Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #3 on: March 03, 2009, 04:04:14 AM »
From your code I'd guess the last line should be wndControl->SetFont(font_fixedw_); as wndControl is declared as a CWnd pointer. But as I say, I'd guess :)

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #4 on: March 03, 2009, 06:45:16 AM »
Hi,

I have tried these two lines in different ways including the ways below.

Code: C++
  1. CWnd *wndControl = GetDlgItem(IDC_Word);
  2. wndControl.SetFont(font_fixedw_);
  3.  
  4. CWnd wndControl = new CWind;
  5. wndControl = GetDlgItem(IDC_Word);
  6. wndControl.SetFont(font_fixedw_);
  7.  
  8. CWnd wndControl = GetDlgItem(IDC_Word);
  9. wndControl.SetFont(font_fixedw_);
  10.  
  11. CWnd *wndControl = GetDlgItem(IDC_Word);
  12. wndControl->SetFont(font_fixedw_);
  13.  

All of them seem to give me a error. Not sure what to do now.


Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #5 on: March 03, 2009, 07:38:50 AM »
I don't really know with MFC but you probably have to Attach the CWnd class you're creating to the existing Dialog control. Honestly though I'm not sure.

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #6 on: March 03, 2009, 09:03:49 AM »
Hi,

I got it to build. I did it by adding a control variable called C_word to the Static text control and the removing the following two lines and adding this one.

Code: C++
  1. //CWnd *wndControl  = GetDlgItem(IDC_Word);
  2. //wndControl.SetFont(font_fixedw_,TRUE);
  3.  
  4. C_Word.SetFont(&font_fixedw_);
  5.  

However are text does not seem to get bigger.
I will keep playing with it.

Thanks for your Help.

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #7 on: March 03, 2009, 11:38:53 PM »
Hi Again

Just to let you know I did it in three lines of code.

Code: C++
  1. CFont *m_Word = new CFont;
  2. m_Word->CreatePointFont(600, _T("Arial") );
  3. C_Word.SetFont(m_Word); //C_Word is a control variable for the Static text control
  4.  

I thought there is a easy way to do it just did not know how, Thanks again for your help.


tez93

  • Participant
  • Joined in 2009
  • *
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Static Text Control Font Size
« Reply #8 on: April 02, 2009, 05:47:50 AM »

I was trying to work out how to do this myself recently and came up with another method as Visual Studio didn't seem to want to let me create a control variable for a static text control within a dialog.

Code: C++
  1.  
  2. CFont* g_hFont = NULL;
  3.  
  4. ...
  5.  
  6. case WM_INITDIALOG:
  7. {
  8.         if (g_hFont)
  9.         {
  10.                 delete g_hFont;
  11.                 g_hFont = NULL;
  12.         }
  13.  
  14.         g_hFont = new CFont;
  15.         g_hFont->CreatePointFont(140, _T("Verdana"));
  16.         CWnd::FromHandle(GetDlgItem(hDlg, IDC_STATIC_NAME))->SetFont(g_hFont, TRUE);
  17.  
  18.         return (INT_PTR)TRUE;
  19. }
  20.  
  21. ...
  22.  
  23.