|
-
January 19th, 2010, 04:53 PM
#1
Changing Label Size/Font help
Hello, I'm having a very difficult time changing parameters to a program that has a few labels. I was able to move their position, change their color, but unfortunately not their sizes.
m_lblctrl1.SetWindowPos(&wndBottom,0,0,0,0,SWP_NOSIZE);
changes m_lblctrl1 position (x,y,cx,cy)
m_lblctrl1.SetForeColor(RGB(255,0,0));
changes m_lblctrl1 to red.
m_lblctrl1.SetFont(LPFONTDISP);
now this is where i've been hitting a very bad wall
this is the other method i've been tackling as well.
LOGFONT lf;
lf.lfHeight = 16;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = ANSI_CHARSET;
lf.lfQuality = PROOF_QUALITY;
lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
_tcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), _T("Arial"));
m_lblctrl1.SetFont(&lf);
the error i'm getting is "error C2664: 'CLabel::SetFont' : cannot convert parameter 1 from 'LOGFONT *' to 'LPFONTDISP' " I've done all the research i could do to properly troubleshoot this, but unfortunately i've hit the point where i need professional help. m_lblctrl1 is defined as a CLabel in case that helps. Also i used Do Data Exchange from the original label defined:
DDX_Control(pDX, IDC_LBLCTRL1, m_lblctrl1);
Thank you for any input, if there is any details i left out, I'd gladly add it.
-David
-
January 20th, 2010, 06:51 AM
#2
Re: Changing Label Size/Font help
From MSDN:
CWnd::SetFont
void SetFont( CFont* pFont, BOOL bRedraw = TRUE );
....
1. As you can see, you have to have a CFont instance to pass its pointer to CWnd::SetFont. This instance must exist until m_lblctrl1 will be destroyed. So the best way would be to create a CFont class member...
2. This CFont class member must have a font that you create using CFont::CreateFontIndirect or CFont::CreatePointFontIndirect and passing the pointer to LOGFONT structure (lf in your code snippet) to it.
Victor Nijegorodov
-
January 20th, 2010, 08:59 AM
#3
Re: Changing Label Size/Font help
Ok, this is definitely great advice and a push in the right direction. For your CFont class suggestion, i quickly added "CFont m_lblfont;" to the header and tried compiling with
LOGFONT lf;
lf.lfHeight = 16;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = ANSI_CHARSET;
lf.lfQuality = PROOF_QUALITY;
lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
_tcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), _T("Arial"));
m_lblfont.SetFont(&lf);
I got the following error "error C2039: 'SetFont' : is not a member of 'CFont' "
Also, I don't quiet understand what you mean by your second statement. Would you please elaborate.
Thank you!
-
January 20th, 2010, 09:16 AM
#4
Re: Changing Label Size/Font help
For a LOGFONT struct, you want to use CreateFontIndirect().
Code:
m_lblfont.CreateFontIndirect(&lf);
-
January 20th, 2010, 09:18 AM
#5
Re: Changing Label Size/Font help
 Originally Posted by Dragondima
Ok, this is definitely great advice and a push in the right direction. For your CFont class suggestion, i quickly added "CFont m_lblfont;" to the header and tried compiling with
LOGFONT lf;
...
lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
_tcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), _T("Arial"));
m_lblfont.SetFont(&lf);
I got the following error "error C2039: 'SetFont' : is not a member of 'CFont' "
Yes, of course! Because 'SetFont' is a method of CWnd class (and I pointed it out in my previous post)
You should use:
Code:
m_lblctrl1.SetFont(&m_lblfont);
But before you must create this m_lblfont font!
 Originally Posted by Dragondima
Also, I don't quiet understand what you mean by your second statement. Would you please elaborate.
Thank you!
CFont::CreatePointFontIndirect
CFont::CreateFontIndirect
CFont Class
Victor Nijegorodov
-
January 20th, 2010, 09:50 AM
#6
Re: Changing Label Size/Font help
Thank you! I'll be working on that right now. I apologize i'm very new at C++ and didn't understand quiet everything you said, so if i was repetitive, I'm sorry. Thank you again, and i'll let you all know how it turns out.
-David
-
January 20th, 2010, 09:55 AM
#7
Re: Changing Label Size/Font help
 Originally Posted by hoxsiew
For a LOGFONT struct, you want to use CreateFontIndirect().
Code:
m_lblfont.CreateFontIndirect(&lf);
I compiled it with the m_lblfont.CreateFontIndirect(&lf);
but i'm trying to change the size of m_lblctrl1 which is a CLabel. How do i set the m_lblctrl1 with this m_lblfont?
-
January 20th, 2010, 09:58 AM
#8
Re: Changing Label Size/Font help
 Originally Posted by Dragondima
but i'm trying to change the size of m_lblctrl1 which is a CLabel. How do i set the m_lblctrl1 with this m_lblfont?
See the Post#5
Victor Nijegorodov
-
January 20th, 2010, 10:04 AM
#9
Re: Changing Label Size/Font help
Ok please ignore my last post. It was done hastily.
Just to recap as to where i am now. Thank's VictorN for your help, where i'm stuck(confused) is here.
So i created my CFont font;
I used these values that were provided from your msdn link:
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // zero out structure
lf.lfHeight = 12; // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial"
VERIFY(font.CreateFontIndirect(&lf)); // create the font
now i'm trying to set it to my Clabel m_lblctrl1.
m_lblctrl1.SetFont(&font);
but i'm still getting the same error message i was getting before
"error C2664: 'CLabel::SetFont' : cannot convert parameter 1 from 'CFont *' to 'LPFONTDISP' "
I'm a little confused as to what i'm doing wrong. I think i'm follow your directions correctly, but can't seem to get it right.
-
January 20th, 2010, 10:15 AM
#10
Re: Changing Label Size/Font help
 Originally Posted by Dragondima
but i'm still getting the same error message i was getting before
"error C2664: 'CLabel::SetFont' : cannot convert parameter 1 from 'CFont *' to 'LPFONTDISP' "
I'm a little confused as to what i'm doing wrong. I think i'm follow your directions correctly, but can't seem to get it right.
Are you working with an ActiveX control?
Then have a look at http://msdn.microsoft.com/en-us/libr...74(VS.60).aspx
Victor Nijegorodov
-
January 20th, 2010, 10:20 AM
#11
Re: Changing Label Size/Font help
Sorry i guess that was a vital part i left out. Yes i am working with ActiveX
-
January 20th, 2010, 10:27 AM
#12
Re: Changing Label Size/Font help
 Originally Posted by Dragondima
Yes i am working with ActiveX
I don't use ActiveX, so I'm afraid I cannot help you more.
Victor Nijegorodov
-
January 20th, 2010, 10:38 AM
#13
Re: Changing Label Size/Font help
 Originally Posted by VictorN
I don't use ActiveX, so I'm afraid I cannot help you more.
I still really appreciate all your help! It was a good experience for me asking help within a forum and getting such great feedback! Thank you for your help. If anyone else has any useful input i'd greatly appreciate it.
-
January 29th, 2010, 09:23 AM
#14
Re: Changing Label Size/Font help
Since I take a lot from this Forum, and enjoy helping out. I'd like to share the solution that I received to my own problem.
COleFont newFont;
newFont= m_label.GetFont();
newFont.SetName(_T("Courier New"));
COleCurrency oleCurrency(0, 180000);
newFont.SetSize(oleCurrency.m_cur);
newFont.SetBold(TRUE);
newFont.SetItalic(TRUE);
m_label_breathing.SetFont((LPFONTDISP)newFont.m_lpDispatch);
m_label.SetFont((LPFONTDISP)newFont.m_lpDispatch);
I hope if anyone is looking for a solution for this and sees this thread, that this post helps them. If there are any questions please feel free to message me. This solution was derived from ActiveX documentation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|