|
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
|
|
|
|
|
|
The underst Line of the gradient fill looks bad, it does not look how it should. In the example it looks so bad too. It is just the underst line.
|
|
|
|
|
I have fixed the error on my self, just add one pixel to the bottom when drawing the rect. Here the whole code for the BK Function:
<br />
<br />
void CLabel::DrawGradientFill(CDC* pDC, CRect* pRect, COLORREF crStart, COLORREF crEnd, int nSegments)<br />
{<br />
<br />
COLORREF cr;<br />
int nR = GetRValue(crStart);<br />
int nG = GetGValue(crStart);<br />
int nB = GetBValue(crStart);<br />
<br />
int neB = GetBValue(crEnd);<br />
int neG = GetGValue(crEnd);<br />
int neR = GetRValue(crEnd);<br />
<br />
if(nSegments > pRect->Width())<br />
nSegments = pRect->Width();<br />
<br />
int nDiffR = (neR - nR);<br />
int nDiffG = (neG - nG);<br />
int nDiffB = (neB - nB);<br />
<br />
int ndR = 256 * (nDiffR) / (max(nSegments,1));<br />
int ndG = 256 * (nDiffG) / (max(nSegments,1));<br />
int ndB = 256 * (nDiffB) / (max(nSegments,1));<br />
<br />
nR *= 256;<br />
nG *= 256;<br />
nB *= 256;<br />
<br />
neR *= 256;<br />
neG *= 256;<br />
neB *= 256;<br />
<br />
int nCX = pRect->Width() / max(nSegments,1), nLeft = pRect->left, nRight;<br />
pDC->SelectStockObject(NULL_PEN);<br />
<br />
for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)<br />
{<br />
<br />
if (i == (nSegments - 1))<br />
nRight = pRect->right;<br />
else<br />
nRight = nLeft + nCX;<br />
<br />
cr = RGB(nR / 256, nG / 256, nB / 256);<br />
<br />
{<br />
CBrush br(cr);<br />
CBrush* pbrOld = pDC->SelectObject(&br);<br />
pDC->Rectangle(nLeft, pRect->top, nRight + 1, pRect->bottom+1);<br />
pDC->SelectObject(pbrOld);<br />
}<br />
<br />
<br />
nLeft = nRight;<br />
}<br />
}<br />
|
|
|
|
|
You know these green little tootltips which are shown when you get over an area with the mouse. It would be nice if you could insert such a feature.
It is a very nice class.
|
|
|
|
|
Nitromouse wrote:
green little tootltips
r u mean the system defaults you're using!
|
|
|
|
|
|
I have an SDI application
I need the back color of SDI in another color than Grey
could you suggest how to do that?
|
|
|
|
|
Override OnCtlColor and for nCtlColor == CTLCOLOR_DLG return a brush with the colour of your choice.
Norberto
|
|
|
|
|
Hello,
I have a problem using CLabel on property pages.
In XP, with visual theme on, the property pages gets a gradient(white) background color, but
the static controls still have an ugly gray background (probably because of COLOR_3DFACE?).
If I return NULL in CtlColor() , everything works, except when I go back in classic mode,
then, the textcolor doesn't work anymore
any ideas ?
|
|
|
|
|
OK, I need SetTransparency()
dumb & dumber
|
|
|
|
|
About 17 lines from the end of OnPaint(), in "Label.cpp", is the end of this "if" statement:
if(m_bRotation)
... etc.
if(m_3dType == Raised)
rc.OffsetRect(-1, -1);
else
rc.OffsetRect(1, 1);
pDCMem->DrawText(strText, rc, dwFlags);
m_3dType;
=======================
The object, "m_3dType" serves no purpose there.
William
|
|
|
|
|
So simple and work in one minute!
JW
|
|
|
|
|
Your welcome john!
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
m_static01.Create(_T("Test"), WS_CHILD|WS_VISIBLE, CRect(0, 0, 600, 50), this, -1);
I use this in a view, but it is wrong.
|
|
|
|
|
no not at all, in the View when its create you may want to a WS_CLIPCHILDREN?
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
Tooltips doesn't work in example code???
|
|
|
|
|
The CLabel code is really nice.
But there is a small problem, the Label flicks when the text changed frequently. Here is how I fixed it, hope that I am doing right:
In CLabel::CLabel(), add
{
...
m_strText = "";
...
}
Change SetText to this:
CLabel& CLabel::SetText(const CString& strText)
{
m_strText = strText;
//SetWindowText( strText );
UpdateSurface();
return *this;
}
and change UpdateSurface() to this:
void CLabel::UpdateSurface()
{
//CRect (rc);
//GetWindowRect(rc);
RedrawWindow();
//GetParent()->ScreenToClient(rc);
//GetParent()->InvalidateRect(rc,TRUE);
//GetParent()->UpdateWindow();
}
in OnPain() add
{
......
//GetWindowText(strText);
if( m_strText == "" )
GetWindowText(m_strText);
strText = m_strText;
......
}
Now the flick gone.
|
|
|
|
|
Thanks!!
Flicker's gone!!
William
|
|
|
|
|