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
Re: Changing Label Size/Font help
From MSDN:
Quote:
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.
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!
Re: Changing Label Size/Font help
For a LOGFONT struct, you want to use CreateFontIndirect().
Code:
m_lblfont.CreateFontIndirect(&lf);
Re: Changing Label Size/Font help
Quote:
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!
Quote:
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
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
Re: Changing Label Size/Font help
Quote:
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?
Re: Changing Label Size/Font help
Quote:
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
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.
Re: Changing Label Size/Font help
Quote:
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
Re: Changing Label Size/Font help
Sorry i guess that was a vital part i left out. Yes i am working with ActiveX
Re: Changing Label Size/Font help
Quote:
Originally Posted by
Dragondima
Yes i am working with ActiveX
I don't use ActiveX, so I'm afraid I cannot help you more.
Re: Changing Label Size/Font help
Quote:
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.
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.