 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks very much for the code!
By default, set byCharSet=ANSI_CHARSET, the font doesn't work in some languages such as Simplified Chinese.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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 ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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):
/////////////////////////////////////////////////////// // // Set up for double buffering... // 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 = &dc; 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); // continue DC restore pDCMem->SelectObject ( pOldBitmap ) ; delete pDCMem; }
Add just below that:
else { dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCAND); // continue DC restore 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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I have a problem that all the label disappear after I call SetWindowPos function. Anyone has any idea?
Thanks a lot.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have had the same problem!
I removed the function call GetParent()->UpdateWindow() from void CLabel::UpdateSurface().
Now everthing runs fine
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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. CString m_strText; // Label Text // (Add) for Protecting Flicker(EastSeaBoy)
1. void CLabel::OnPaint() { ..... // GetWindowText(strText); // (Del) for Protecting Flicker(EastSeaBoy) strText = m_strText; // (Add) for Protecting Flicker(EastSeaBoy) ..... }
2. CLabel& CLabel::SetText(const CString& strText) { if(IsWindow(this->GetSafeHwnd())) { //SetWindowText(strText); // (Del) for Protecting Flicker(EastSeaBoy) m_strText = strText; // (Add) for Protecting Flicker(EastSeaBoy) UpdateSurface(); } return *this; }
========================================== Right?
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 3.67/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
Has anyone come up with a fix for setting the window state ( EnableWindow(FALSE) ) in OnInitDialog?
Yofnik
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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"); m_static.SetTransparent(TRUE); 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
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
'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
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
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=-
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |