|
Hi! A Very useful article!!
I am doing DDX_Control with RichEdit control in my form view to the member variable of your CLabel.
Everything is working fine except SetFontSize() for me.
I am displaying link using SetText() and SetHyperLink() functions.
How to change the caption's font size(which is set using SetText()) displayed in control?
Any suggestion will be very helpful..
Thanks..
modified on Wednesday, January 21, 2009 10:41 AM
|
|
|
|
|
I had some flashing problems on transparent label redraw when they are positioned over a bitmap drawned dynamically. I fixed the problem with the following changes.
CLabel& CLabel::SetText(const CString& strText)
{
if(IsWindow(this->GetSafeHwnd()))
{
SetRedraw(FALSE);
SetWindowText(strText);
SetRedraw(TRUE);
UpdateSurface();
}
return *this;
}
void CLabel::UpdateSurface()
{
CRect (rc);
GetWindowRect(rc);
//RedrawWindow();
GetParent()->ScreenToClient(rc);
GetParent()->InvalidateRect(rc,TRUE);
GetParent()->UpdateWindow();
}
Thanks for your good class
|
|
|
|
|
Thanks very much for the code!
By default, set byCharSet=ANSI_CHARSET, the font doesn't work in some languages such as Simplified Chinese.
|
|
|
|
|
Thanks for this class.
Is it possible to change alignment to right aligned (for numeric number) ?
And also to change vertical alignement to bottom aligned ?
|
|
|
|
|
Is it possible to rotate bitmaps? Thanks for a great piece of code.
|
|
|
|
|
Hello,
I am using CLabel in an application and I am trying to set a background image to it.
I added some new methods for this and I intended to override DrawItem to repaint the control.
However, the DrawItem method doesn't seem to be called from anywhere. From what I understood from the documentation, I must set the style of the control to SS_OWNERDRAW (I do this in PreSubClassWindow).
It still doesn't work.
Could you give me a hand here?
Thanks a lot.
Ovidiu
|
|
|
|
|
I'm looking for information on using this code in a commercial product. I see no copyright or license information on this site or in the code so I'm assuming it's free to use, but I'd like to be sure. And since I can't find a way to send a message directly to the author I'm positing here.
Thanks.
|
|
|
|
|
I'm the author of this control, please use it freely without any restrictions at all.
Norm Almond
Software Kinetics
.net is a box of never ending treasures, every day I get find another gem.
|
|
|
|
|
Hi great code thanks !
I tried enabling / disabling your CLabel via:
myLabel.EnableWindow(FALSE);
myLabel.EnableWindow(TRUE);
All the set formating seems to disappear !?
Bug ?
Thanks
Chris
|
|
|
|
|
This has been one of my all time favorite classes over the years.
So much so, that I've used it lots of times to dress up quick projects.
I recently downloaded and updated my files to see if I could resolve an issue I had with flashing text on-off-on inadvertently wiping out the text value.
Unfortunately, it looks like this version is a LOT slower to refresh than the old one. For example I have about 50 small little CLabels on my latest dialog project that I use as little colored status indicators as I read in a text file. Because this file reader reads in hundreds of lines at a shot when I first start, I watch my labels flash madly until it is loaded.
The newest verion 1.6 really bogs down updating the labels compared to my old version (I'm guessing I had 1.1, but I'm not sure there is no comment at top). I'm guessing that each functions call to UpdateSurface()precludes you from making a lot of calls in a row.
The real killer is that my flashing background problem still seems to be there. Has anyone else noticed FlashBackground(FALSE) + FlashBackground(TRUE) + FlashBackground(FALSE) ... seems to disable the flashing ability?
A++ for a great little class over the years.
B+ for keeping up with it and adding new even cooler features
C- for allowing the feature creep to impair performance.
|
|
|
|
|
Just in case anyone is interested, I figured out a way to draw the CLabel such that it looks like colored glass with text on it, hovering over the background (semi-transparent but with color).
Here's what you do:
All of this code modification is in the OnPaint function
Here's the original section (near the beginning of OnPaint):
CDC* pDCMem;
CBitmap* pOldBitmap = NULL;
if (!m_bTransparent)
{
pDCMem = new CDC;
pDCMem->CreateCompatibleDC(&dc);
bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
pOldBitmap = pDCMem->SelectObject(&bmp);
}
Replace the existing "else" right below that, with the following:
else
{
pDCMem = new CDC;
pDCMem->CreateCompatibleDC(&dc);
bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
pOldBitmap = pDCMem->SelectObject(&bmp);
CBrush brush;
brush.CreateSolidBrush(RGB(122,255,122));
pDCMem->FillRect(rc, &brush);
}
What this part does is create a compatible bitmap in memory and paints it a light shade of green (you can obvious change the color as you see fit).
Then down at the bottom of the function, is the original code:
if (!m_bTransparent)
{
dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY);
pDCMem->SelectObject ( pOldBitmap ) ;
delete pDCMem;
}
Add just below that:
else
{
dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCAND);
pDCMem->SelectObject ( pOldBitmap ) ;
delete pDCMem;
}
All of this occurs after the text has been drawn. So what you have is a bitmap in memory of a light green colored rectangle with text drawn on it. What this last section of code does is BitBlt that onto the background using SRCAND which combines the source and destination using a logical AND.
There you go... semi-transparent with color.
|
|
|
|
|
I have a problem that all the label disappear after I call SetWindowPos function. Anyone has any idea?
Thanks a lot.
|
|
|
|
|
I have had the same problem!
I removed the function call GetParent()->UpdateWindow()
from void CLabel::UpdateSurface().
Now everthing runs fine
|
|
|
|
|
Hello, I am having the problem with screen flickerring when the label is repeatly painted. I noticed that the double buffer is only applied when m_bTransparent = FALSE in the OnPaint() function. How to avoid the flickerinf problem for the transperent label?
Thank you very much for your help.
|
|
|
|
|
This class is great!!! WOW~~!
I had have the same problem.
I solved that like Following Code.
EastSeaBoy is my nickname.
=========================================
0. ADD a Member Variable.<br />
CString m_strText;
<br />
<br />
1. void CLabel::OnPaint() <br />
{<br />
.....<br />
strText = m_strText;
.....<br />
}<br />
<br />
2. CLabel& CLabel::SetText(const CString& strText)<br />
{<br />
if(IsWindow(this->GetSafeHwnd())) <br />
{<br />
m_strText = strText;
UpdateSurface();<br />
}<br />
return *this;<br />
}
==========================================
Right?
|
|
|
|
|
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
|
|
|
|