Welcome Guest.   Make a donation to an author on the site April 16, 2014, 06:11:24 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Learn about the DonationCoder.com microdonation system (DonationCredits).
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Static Text Control Font Size  (Read 7909 times)
Davidtheo
Participant
*
Posts: 119


View Profile Give some DonationCredits to this forum member
« 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
Logged

EĆ³in
Charter Member
***
Posts: 1,400


O'Callaghan

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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.

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  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.
Logged

Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.
Davidtheo
Participant
*
Posts: 119


View Profile Give some DonationCredits to this forum member
« 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.

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  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

Logged

EĆ³in
Charter Member
***
Posts: 1,400


O'Callaghan

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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 smiley
Logged

Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.
Davidtheo
Participant
*
Posts: 119


View Profile Give some DonationCredits to this forum member
« Reply #4 on: March 03, 2009, 06:45:16 AM »

Hi,

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

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  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_);

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

Logged

EĆ³in
Charter Member
***
Posts: 1,400


O'Callaghan

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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.
Logged

Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.
Davidtheo
Participant
*
Posts: 119


View Profile Give some DonationCredits to this forum member
« 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.

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  1. //CWnd *wndControl  = GetDlgItem(IDC_Word);
  2. //wndControl.SetFont(font_fixedw_,TRUE);
  3.  
  4. C_Word.SetFont(&font_fixedw_);

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

Thanks for your Help.
Logged

Davidtheo
Participant
*
Posts: 119


View Profile Give some DonationCredits to this forum member
« 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.

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  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

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

Logged

tez93
Participant
*
Posts: 1


View Profile Give some DonationCredits to this forum member
« 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.

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  1. CFont* g_hFont = NULL;
  2.  
  3. ...
  4.  
  5. case WM_INITDIALOG:
  6. {
  7. if (g_hFont)
  8. {
  9. delete g_hFont;
  10. g_hFont = NULL;
  11. }
  12.  
  13. g_hFont = new CFont;
  14. g_hFont->CreatePointFont(140, _T("Verdana"));
  15. CWnd::FromHandle(GetDlgItem(hDlg, IDC_STATIC_NAME))->SetFont(g_hFont, TRUE);
  16.  
  17. return (INT_PTR)TRUE;
  18. }
  19.  
  20. ...

Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.077s | Server load: 0.24 ]