|
After modify the code, you should call SetText() to show a text when you want to show something. Just like this:
m_label
.SetTextColor(F_C_NOCONNECT)
.SetText("No connect") <--------------notice this
.ShowWindow(SW_SHOW);
If you do not call SetText(), this label can not be visible, even it already has a text you enterd in the VC Text Properties window.
|
|
|
|
|
you are great!
thank you!!!
|
|
|
|
|
There is more code if you want to catch all cases:
BOOL CLabel::Create(LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
m_sText = lpszText;
return CStatic::Create(lpszText, dwStyle, rect, pParentWnd, nID);
}
and
void CLabel::PreSubclassWindow()
{
CStatic::PreSubclassWindow();
CString sText;
GetWindowText(sText);
if(m_sText.IsEmpty() && ! sText.IsEmpty())
m_sText = sText;
CFont* cf = GetFont();
if(cf != NULL)
cf->GetObject(sizeof(m_lf), &m_lf);
else
GetObject(GetStockObject(SYSTEM_FONT), sizeof(m_lf), &m_lf);
ReconstructFont();
}
|
|
|
|
|
Hello, I need to change the transparent label text every 500MS with graphic background. It shows a white flash sometimes when it is repainted. Any idea to improve this?
Thank you very much.
|
|
|
|
|
I can't vote (5) for the article more than once! Good job as usual, Norm!
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Has anyone come up with a fix for setting the window state ( EnableWindow(FALSE) ) in OnInitDialog?
Yofnik
|
|
|
|
|
Just an FYI:
The line in Label.cpp with "mailto:" breaks UNICODE compatibility. I see you've used _T() with other literals, so that one probably just slipped through... You may want to issue a quick article update.
--
Edward Livingston
(aka ExtraLean)
--
"I still maintain that seeing a nipple is far less disturbing than seeing someone get their brains blown out." -- Chris Maunder
|
|
|
|
|
Hi guys,
Am trying to use CLabel in a skinned dialog app. now the problem is sometimes when I set the text of the control using SetWindowText there is no transparency any more.
e.g in OnInitDialog
m_static.SetWindowText("Hello world");<br />
m_static.SetTransparent(TRUE);<br />
m_static.SetWindowText("Wassup?");
this works fine, but when i have something like this in a button click handler
m_static.SetWindowText("Testing ");
the background appears and i have to SetTransparent again for it to become transparent.
I don't think this is the way it should work..any suggestions? thanx
|
|
|
|
|
|
'LoadCursorA' : cannot convert parameter 2 from 'const int' to 'const char *'
m_stcMail.SetMailLink(TRUE,FALSE)
.SetTextColor(RGB(0,0,255))
.SetFontUnderline(TRUE)
.SetLinkCursor(LoadCursor(NULL,IDC_HAND));
m_link.SetLink(TRUE,FALSE)
.SetTextColor(RGB(0,0,255))
.SetFontUnderline(TRUE)
.SetLinkCursor(LoadCursor(NULL, IDC_HAND));
Marcus Carey
|
|
|
|
|
add
#define IDC_HAND MAKEINTRESOURCE(32649)
|
|
|
|
|
I am creating a subclass of CWnd that I create dynamically and add to a dialog. This class contains several CLabels that I create and position myself (no templates involved). So far I have only tried using the SetFontSize and SetTextColor functions, and the color changes but not the font size. I tried calling the same functions with a CLabel that I created on a dialog with a template, and both worked fine.
Here is the code in the Create function of my CWnd subclass:
m_sBP.Create("BP", lStaticStyle, CRect(iDPSplit, iCol1Top, iRightEdge, iCol2Top), this);
m_sBP.SetFontSize(14);
m_sBP.SetTextColor(RGB(255,0,0));
where m_sBP is a CLabel declared in the header file.
Can anyone help me out?
Thanks
-=Connor=-
|
|
|
|
|
I might have just solved my own problem - I changed the font and it seems to be working now.
-=Connor=-
|
|
|
|
|
Has anyone come up with a fix for this yet? If not, does anybody know of another static class that works and can change text attributes?
Tired of my application aborting all the time!!!!
|
|
|
|
|
What leak? The tone of your message stinks, I suggest buddy you FIX it.
To iterate is human, to recurse is devine.
|
|
|
|
|
First off I'm not your buddy. Second my tone was only that of someone looking for a solution since February. Sounds a bit defensive to me.
|
|
|
|
|
Does anybody know how to implement text wrapping for this control?
If I have a single word that is longer than the width of the static it is cut off. Word break style wont do the trick since its a single wordthat is bigger than the static.
Any Ideas
|
|
|
|
|
Quick hack, at least work as my usage
change the OnPaint() function in CLabel.cpp, from the 3D part to the end of the function
//
// 3333 DDDDD
// 3 D D
// 33 D D E F X
// 3 D D
// 3333 DDDDD
//
//
if (m_bRotation)
{
int nAlign = pDCMem->SetTextAlign (TA_BASELINE);
CPoint pt;
GetViewportOrgEx (pDCMem->m_hDC,&pt) ;
SetViewportOrgEx (pDCMem->m_hDC,rc.Width() / 2, rc.Height() / 2, NULL) ;
pDCMem->TextOut (0, 0, strText) ;
SetViewportOrgEx (pDCMem->m_hDC,pt.x / 2, pt.y / 2, NULL) ;
pDCMem->SetTextAlign (nAlign);
}
else
{
CRect newRC;
TEXTMETRIC tag;
CSize sz;
CString s = (LPCTSTR)strText;
::GetTextExtentPoint32(pDCMem->GetSafeHdc(), strText,
strText.GetLength(), &sz);
CStringArray asText;
int nLine = 1;
CString s2;
int nIdx, nX = 0;
if (sz.cx > rc.Width())
{
s2.Empty();
// need wrapping
while (s.GetLength() > 0)
{
nIdx = s.Find(' ', 0);
if (nIdx != -1)
{
::GetTextExtentPoint32(pDCMem->GetSafeHdc(),
s.Left(nIdx+1), s.Left(nIdx+1).GetLength(), &sz);
if (nX + sz.cx > rc.Width())
{
nX = 0;
nLine++;
asText.SetAtGrow(nLine-1, s2);
TRACE1("%s\n", s2);
s2.Empty();
}
else
{
nX += sz.cx;
s2 += (LPCTSTR)s.Left(nIdx + 1);
s = s.Right(s.GetLength() - nIdx -1);
}
}
else
{
if (s2.GetLength() > 0)
{
nLine++;
asText.SetAtGrow(nLine-1, s2);
s2.Empty();
}
::GetTextExtentPoint32(pDCMem->GetSafeHdc(),
s, s.GetLength(), &sz);
if (sz.cx < rc.Width())
{
nLine++;
asText.SetAtGrow(nLine-1, s);
TRACE1("%s\n", s);
s.Empty();
}
else // no space inside
{
for (int i=0; i<s.GetLength(); i++)
{
::GetTextExtentPoint32(pDCMem->GetSafeHdc(),
s.Left(i), i, &sz);
if (sz.cx > rc.Width())
{
nLine++;
asText.SetAtGrow(nLine-1, s.Left(i-1));
s = s.Right(s.GetLength() - i);
break;
}
}
}
}
}
}
else
{
asText.SetAtGrow(0, strText);
}
pDCMem->GetTextMetrics(&tag);
LONG nDiff = rc.bottom - rc.top - tag.tmHeight * nLine - 2;
if (nDiff > 0)
{
newRC.left = rc.left;
newRC.top = rc.top + nDiff/2;
newRC.right = rc.right;
newRC.bottom = newRC.top + tag.tmHeight + 1;
}
else
newRC = rc;
CRect newRC2;
for (int i=0; i<nLine; i++)
{
newRC2.top = newRC.top + tag.tmHeight * i;
newRC2.left = newRC.left;
newRC2.right = newRC.right;
newRC2.bottom = newRC2.top + tag.tmHeight;
TRACE1("%s\n", asText[i]);
pDCMem->DrawText(asText[i],newRC2,dwFlags);
if (m_bFont3d)
{
pDCMem->SetTextColor(m_cr3DHiliteColor);
if (m_3dType == Raised)
newRC2.OffsetRect(-1,-1);
else
newRC2.OffsetRect(1,1);
pDCMem->DrawText(asText[i],rc,dwFlags);
m_3dType;
}
}
}
// Restore DC's State
pDCMem->SetBkMode(nMode);
pDCMem->SelectObject(pOldFont);
pDCMem->SetTextColor(crText);
if (!m_bTransparent)
{
dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY);
// continue DC restore
pDCMem->SelectObject ( pOldBitmap ) ;
delete pDCMem;
}
|
|
|
|
|
Has anyone come up with a fix for the memory leak in version 1.6?
|
|
|
|
|
After opening and closing a dialog a few times with the CLabel control, the GDI Objects stop decrementing.
|
|
|
|
|
I'll take a look and post a maintenace version soon.
|
|
|
|
|
Hi Norm,
First of all, I want to thank you for your great job. I use it in my project, very helpful. I just found that there is system resource leak under Window 98, I need to change the label text every second, it becomes a big issue for me. However, I didn't see the problem with Window 2000/XP. Any idea? I appreciate your any help.
Thanks a lot.
|
|
|
|
|
Curious, I don't see the HCURSOR object ever being deleted.
|
|
|
|
|
System cursors don't get deleted
I am that is
|
|
|
|
|
|