| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359 |
- // Label.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Label.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- BEGIN_MESSAGE_MAP(CLabel, CStatic)
- //{{AFX_MSG_MAP(CLabel)
- ON_WM_TIMER()
- ON_WM_LBUTTONDOWN()
- ON_WM_SETCURSOR()
- ON_WM_SYSCOLORCHANGE()
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- ON_WM_CTLCOLOR_REFLECT()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CLabel Version 1.2
- //
- // From now on I'll try to keep a log of fixes and enhancements...
- //
- // The new feature were added due to the response of people.
- // All I ask is to all you programmers out there, is if you add, fix or
- // enhance this code, sent me a copy and I'll send the copy on to www.codeproject.com
- //
- // Happy Software Engineer :)
- //
- // New features include:
- //
- // A. Support for 3D Fonts
- // B. Support for background transparency
- // C. More comments provided
- // D. If alignment is 'centered' and the window text is seperated by '\r\n'
- // the will be centered accordingly - requested by someone @ nasa ;)
- // E. Support for font rotation.
- // F. Respond to System Color Change
- // G. OnPaint improved performance - using Double Buffering Technique
- //
- // Thanks to:
- // Mark McDowell - For suggestion on 'Increasing the flexibility of "hypertext" setting...'
- // Erich Ruth - For suggestion on 'Font Rotation'
- //
- /////////////////////////////////////////////////////////////////////////////
- // CLabel Version 1.3
- //
- // A. Added SS_LEFTNOWORDWRAP to include wordwrap
- // B. Fix repainting problem
- // C. Fix SetBkColor
- // D. Added SS_CENTER
- // Thanks to:
- // Marius - Added styling problem.
- // Azing Vondeling & Broker - Spotting painting Problem.
- // Mel Stober - Back Color & SS_CENTER
- //
- /////////////////////////////////////////////////////////////////////////////
- // CLabel Version 1.4
- //
- // A. Fix to transparency mode
- // B. Added new SetText3DHiliteColor to change the 3D Font face color - default is white.
- //
- // Thanks to:
- // michael.groeger - Spotting Transparency with other controls bug.
- //
- //
- /////////////////////////////////////////////////////////////////////////////
- // CLabel Version 1.5
- //
- // A. Sanity handle check
- // B. Support Interface Charset
- // C. Check compilition with _UNICODE
- // D. Fix hyperlink feature
- // E. Support default Dialog Font
- // F. Inclusion of SS_OWNERDRAW via control creation and subclassing
- // G. Modification to Text aligmnent code
- // H. New background gradient fill function
- //
- // Thanks to:
- // Steve Kowald - Using null handles
- // Alan Chan - Supporting International Windows
- // Dieter Fauth - Request for default Dialog font
- // Herb Illfelder - Text Alignment code
- //
- /////////////////////////////////////////////////////////////////////////////
- // CLabel Version 1.6
- // Jeroen Roosendaal - SetFont suggestion
- // Laurent - Spotting SelectObject bugs
- // Bernie - Fix PreCreateWindow bug
- // Jignesh I. Patel - Added expanded tabs feature
- // Jim Farmelant - Fix SetText crash
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::CLabel
- //
- // Description: Default contructor
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel::CLabel()
- {
- m_crText = GetSysColor(COLOR_WINDOWTEXT);
- // 1.1
- m_hBackBrush = NULL;
- m_crHiColor = 0;
- m_crLoColor = 0;
- m_bTimer = FALSE;
- m_bState = FALSE;
- m_bTransparent = FALSE;
- m_Link = LinkNone;
- m_hCursor = NULL;
- m_Type = None;
- m_bFont3d = FALSE;
- m_bNotifyParent = FALSE;
- m_bToolTips = FALSE;
- m_bRotation = FALSE;
- m_fillmode = Normal;
- m_cr3DHiliteColor = RGB(255,255,255);
- m_hwndBrush = ::CreateSolidBrush(GetSysColor(COLOR_3DFACE));
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::~CLabel
- //
- // Description:
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- // NT ALMOND 15092000 1.5 Handle Check
- //////////////////////////////////////////////////////////////////////////
- CLabel::~CLabel()
- {
- // Clean up
- m_font.DeleteObject();
- ::DeleteObject(m_hwndBrush);
- // Stop Checking complaining
- if (m_hBackBrush)
- ::DeleteObject(m_hBackBrush);
- }
- void CLabel::UpdateSurface()
- {
- CRect (rc);
- GetWindowRect(rc);
- RedrawWindow();
- GetParent()->ScreenToClient(rc);
- GetParent()->InvalidateRect(rc,TRUE);
- GetParent()->UpdateWindow();
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::ReconstructFont
- //
- // Description: Helper function to build font after it was changed
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES: PROTECTED
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- void CLabel::ReconstructFont()
- {
- m_font.DeleteObject();
- BOOL bCreated = m_font.CreateFontIndirect(&m_lf);
- ASSERT(bCreated);
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::OnPaint
- //
- // Description: Handles all the drawing code for the label
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES: Called by Windows... not by USER
- // Probably needs tiding up a some point.
- // Different states will require this code to be reworked.
- //
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 22/10/98 1.0 Origin
- // NT ALMOND 15092000 1.5 Handle Check
- // NT ALMOND 15092000 1.5 Alignment mods
- // NT ALMOND 15092000 1.5 Gradient Fill Mode
- // NT ALMOND 02072002 1.6 Fill SelectObject bugs
- // NT ALMOND 02072002 1.6 Added to expand tabs
- //////////////////////////////////////////////////////////////////////////
- void CLabel::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- DWORD dwFlags = 0;
- CRect rc;
- GetClientRect(rc);
- CString strText;
- GetWindowText(strText);
- CBitmap bmp;
- ///////////////////////////////////////////////////////
- //
- // 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);
- }
- else
- {
- pDCMem = &dc;
- }
- UINT nMode = pDCMem->SetBkMode(TRANSPARENT);
- COLORREF crText = pDCMem->SetTextColor(m_crText);
- CFont *pOldFont = pDCMem->SelectObject(&m_font);
- // Fill in backgound if not transparent
- if (!m_bTransparent)
- {
- if (m_fillmode == Normal)
- {
- CBrush br;
- if (m_hBackBrush != NULL)
- br.Attach(m_hBackBrush);
- else
- br.Attach(m_hwndBrush);
- pDCMem->FillRect(rc,&br);
- br.Detach();
- }
- else // Gradient Fill
- {
- DrawGradientFill(pDCMem, &rc, m_crLoColor, m_crHiColor, 100);
- }
- }
- // If the text is flashing turn the text color on
- // then to the color of the window background.
- LOGBRUSH lb;
- ZeroMemory(&lb,sizeof(lb));
- // Stop Checking complaining
- if (m_hBackBrush)
- ::GetObject(m_hBackBrush,sizeof(lb),&lb);
- // Something to do with flashing
- if (!m_bState && m_Type == Text)
- pDCMem->SetTextColor(lb.lbColor);
- DWORD style = GetStyle();
- switch (style & SS_TYPEMASK)
- {
- case SS_RIGHT:
- dwFlags = DT_RIGHT | DT_WORDBREAK;
- break;
- case SS_CENTER:
- dwFlags = SS_CENTER | DT_WORDBREAK;
- break;
- case SS_LEFTNOWORDWRAP:
- dwFlags = DT_LEFT;
- break;
- default: // treat other types as left
- case SS_LEFT:
- dwFlags = DT_LEFT | DT_WORDBREAK;
- break;
- }
- // Added to expand tabs...
- if(strText.Find(_T('\t')) != -1)
- dwFlags |= DT_EXPANDTABS;
- // If the text centered make an assumtion that
- // the will want to center verticly as well
- if (style & SS_CENTERIMAGE)
- {
- dwFlags = DT_CENTER;
- // Apply
- if (strText.Find(_T("\r\n")) == -1)
- {
- dwFlags |= DT_VCENTER;
- // And because DT_VCENTER only works with single lines
- dwFlags |= DT_SINGLELINE;
- }
- }
- //
- // 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
- {
- pDCMem->DrawText(strText,rc,dwFlags);
- if (m_bFont3d)
- {
- pDCMem->SetTextColor(m_cr3DHiliteColor);
- if (m_3dType == Raised)
- rc.OffsetRect(-1,-1);
- else
- rc.OffsetRect(1,1);
- pDCMem->DrawText(strText,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;
- }
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::OnTimer
- //
- // Description: Used in conjunction with 'FLASH' functions
- //
- // INPUTS: Windows API
- //
- // RETURNS: Windows API
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- void CLabel::OnTimer(UINT nIDEvent)
- {
- m_bState = !m_bState;
- UpdateSurface();
- CStatic::OnTimer(nIDEvent);
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::OnSetCursor
- //
- // Description: Used in conjunction with 'LINK' function
- //
- // INPUTS: Windows API
- //
- // RETURNS: Windows API
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- BOOL CLabel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- if (m_hCursor)
- {
- ::SetCursor(m_hCursor);
- return TRUE;
- }
- return CStatic::OnSetCursor(pWnd, nHitTest, message);
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::OnLButtonDown
- //
- // Description: Called when a link is click on
- //
- // INPUTS: Windows API
- //
- // RETURNS: Windows API
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- // NT ALMOND 02072002 1.6 Added Mail support
- //////////////////////////////////////////////////////////////////////////
- void CLabel::OnLButtonDown(UINT nFlags, CPoint point)
- {
- if (!m_bNotifyParent) // Fix
- {
- CString strLink;
- GetWindowText(strLink);
- if (m_Link == HyperLink)
- {
- ShellExecute(NULL,_T("open"),m_sLink.IsEmpty() ? strLink : m_sLink,NULL,NULL,SW_SHOWNORMAL);
- }
- if (m_Link == MailLink)
- {
- strLink = _T("mailto:") + strLink;
- ShellExecute( NULL, NULL, strLink, NULL, NULL, SW_SHOWNORMAL );
- }
- }
- else
- {
- // To use notification in parent window
- // Respond to a OnNotify in parent and disassemble the message
- //
- NMHDR nm;
- nm.hwndFrom = GetSafeHwnd();
- nm.idFrom = GetDlgCtrlID();
- nm.code = NM_LINKCLICK;
- GetParent()->SendMessage(WM_NOTIFY,nm.idFrom,(LPARAM) &nm);
- }
- CStatic::OnLButtonDown(nFlags, point);
- }
- //////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////
- // THE FUNCTIONS START HERE :----
- //////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetText
- //
- // Description: Short cut to set window text - caption - label
- //
- // INPUTS: Text to use
- //
- // RETURNS: Reference to this
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26081998 1.0 Origin
- // NT ALMOND 02072002 1.6 Crash Fix
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetText(const CString& strText)
- {
- if(IsWindow(this->GetSafeHwnd()))
- {
- SetWindowText(strText);
- UpdateSurface();
- }
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetTextColor
- //
- // Description: Sets the text color
- //
- // INPUTS: True or false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 22/10/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetTextColor(COLORREF crText)
- {
- m_crText = crText;
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFontBold
- //
- // Description: Sets the font ot bold
- //
- // INPUTS: True or false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 22/10/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFontBold(BOOL bBold)
- {
- m_lf.lfWeight = bBold ? FW_BOLD : FW_NORMAL;
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFontUnderline
- //
- // Description: Sets font underline attribue
- //
- // INPUTS: True of false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFontUnderline(BOOL bSet)
- {
- m_lf.lfUnderline = bSet;
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFontItalic
- //
- // Description: Sets font italic attribute
- //
- // INPUTS: True of false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFontItalic(BOOL bSet)
- {
- m_lf.lfItalic = bSet;
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetSunken
- //
- // Description: Sets sunken effect on border
- //
- // INPUTS: True of false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetSunken(BOOL bSet)
- {
- if (!bSet)
- ModifyStyleEx(WS_EX_STATICEDGE,0,SWP_DRAWFRAME);
- else
- ModifyStyleEx(0,WS_EX_STATICEDGE,SWP_DRAWFRAME);
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetBorder
- //
- // Description: Toggles the border on/off
- //
- // INPUTS: True of false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetBorder(BOOL bSet)
- {
- if (!bSet)
- ModifyStyle(WS_BORDER,0,SWP_DRAWFRAME);
- else
- ModifyStyle(0,WS_BORDER,SWP_DRAWFRAME);
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFontSize
- //
- // Description: Sets the font size
- //
- // INPUTS: True of false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFontSize(int nSize)
- {
- CFont cf;
- LOGFONT lf;
- cf.CreatePointFont(nSize * 10, m_lf.lfFaceName);
- cf.GetLogFont(&lf);
- m_lf.lfHeight = lf.lfHeight;
- m_lf.lfWidth = lf.lfWidth;
- // nSize*=-1;
- // m_lf.lfHeight = nSize;
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetBkColor
- //
- // Description: Sets background color
- //
- // INPUTS: Colorref of background color
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetBkColor(COLORREF crBkgnd, COLORREF crBkgndHigh , BackFillMode mode)
- {
- m_crLoColor = crBkgnd;
- m_crHiColor = crBkgndHigh;
- m_fillmode = mode;
- if (m_hBackBrush)
- ::DeleteObject(m_hBackBrush);
- if (m_fillmode == Normal)
- m_hBackBrush = ::CreateSolidBrush(crBkgnd);
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFontName
- //
- // Description: Sets the fonts face name
- //
- // INPUTS: String containing font name
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- // NT ALMOND 15092000 1.5 Support internation windows
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFontName(const CString& strFont, BYTE byCharSet /* Default = ANSI_CHARSET */)
- {
- m_lf.lfCharSet = byCharSet;
- _tcscpy(m_lf.lfFaceName,strFont);
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::FlashText
- //
- // Description: As the function states
- //
- // INPUTS: True or false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::FlashText(BOOL bActivate)
- {
- if (m_bTimer)
- KillTimer(1);
- if (bActivate)
- {
- m_bState = FALSE;
- m_bTimer = TRUE;
- SetTimer(1,500,NULL);
- m_Type = Text;
- }
- else
- m_Type = None; // Fix
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::FlashBackground
- //
- // Description: As the function states
- //
- // INPUTS: True or false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::FlashBackground(BOOL bActivate)
- {
- if (m_bTimer)
- KillTimer(1);
- if (bActivate)
- {
- m_bState = FALSE;
- m_bTimer = TRUE;
- SetTimer(1,500,NULL);
- m_Type = Background;
- }
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetLink
- //
- // Description: Indicates the string is a link
- //
- // INPUTS: True or false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- // NT ALMOND 26/08/99 1.2 Added flexbility of
- // Sending Click meessage to parent
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetLink(BOOL bLink,BOOL bNotifyParent)
- {
- if (bLink)
- m_Link = HyperLink;
- else
- m_Link = LinkNone;
- m_bNotifyParent = bNotifyParent;
- if (m_Link != LinkNone)
- ModifyStyle(0,SS_NOTIFY);
- else
- ModifyStyle(SS_NOTIFY,0);
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetLinkCursor
- //
- // Description: Sets the internet browers link
- //
- // INPUTS: Handle of cursor
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 26/08/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetLinkCursor(HCURSOR hCursor)
- {
- m_hCursor = hCursor;
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetTransparent
- //
- // Description: Sets the Label window to be transpaent
- //
- // INPUTS: True or false
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 22/10/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetTransparent(BOOL bSet)
- {
- m_bTransparent = bSet;
- ModifyStyleEx(0,WS_EX_TRANSPARENT); // Fix for transparency
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFont3D
- //
- // Description: Sets the 3D attribute of the font.
- //
- // INPUTS: True or false, Raised or Sunken
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 22/10/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFont3D(BOOL bSet,Type3D type)
- {
- m_bFont3d = bSet;
- m_3dType = type;
- UpdateSurface();
- return *this;
- }
- void CLabel::OnSysColorChange()
- {
- if (m_hwndBrush)
- ::DeleteObject(m_hwndBrush);
- m_hwndBrush = ::CreateSolidBrush(GetSysColor(COLOR_3DFACE));
- UpdateSurface();
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetRotationAngle
- //
- // Description: Sets the rotation angle for the current font.
- //
- // INPUTS: Angle in Degress
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 22/10/98 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetRotationAngle(UINT nAngle,BOOL bRotation)
- {
- // Arrrrh...
- // Your looking in here why the font is rotating, aren't you?
- // Well try setting the font name to 'Arial' or 'Times New Roman'
- // Make the Angle 180 and set bRotation to true.
- //
- // Font rotation _ONLY_ works with TrueType fonts...
- //
- //
- m_lf.lfEscapement = m_lf.lfOrientation = (nAngle * 10);
- m_bRotation = bRotation;
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetText3DHiliteColor
- //
- // Description: Sets the 3D font hilite color
- //
- // INPUTS: Color
- //
- // RETURNS: Reference to 'this' object
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 17/07/00 1.0 Origin
- //
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetText3DHiliteColor(COLORREF cr3DHiliteColor)
- {
- m_cr3DHiliteColor = cr3DHiliteColor;
- UpdateSurface();
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::PreSubclassWindow
- //
- // Description: Assigns default dialog font
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 15092000 1.5 Origin
- // NT ALMOND 02072002 1.6 Fix crash when GetFont returns NULL
- //////////////////////////////////////////////////////////////////////////
- void CLabel::PreSubclassWindow()
- {
- CStatic::PreSubclassWindow();
- CFont* cf = GetFont();
- if(cf !=NULL)
- {
- cf->GetObject(sizeof(m_lf),&m_lf);
- }
- else
- {
- GetObject(GetStockObject(SYSTEM_FONT),sizeof(m_lf),&m_lf);
- }
- ReconstructFont();
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::PreCreateWindow
- //
- // Description:
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 15092000 1.5 Origin
- //////////////////////////////////////////////////////////////////////////
- BOOL CLabel::PreCreateWindow(CREATESTRUCT& cs)
- {
- return CStatic::PreCreateWindow(cs);
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::DrawGradientFill
- //
- // Description: Internal help function to gradient fill background
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 15092000 1.5 Origin
- //////////////////////////////////////////////////////////////////////////
- void CLabel::DrawGradientFill(CDC* pDC, CRect* pRect, COLORREF crStart, COLORREF crEnd, int nSegments)
- {
- // Get the starting RGB values and calculate the incremental
- // changes to be applied.
- COLORREF cr;
- int nR = GetRValue(crStart);
- int nG = GetGValue(crStart);
- int nB = GetBValue(crStart);
- int neB = GetBValue(crEnd);
- int neG = GetGValue(crEnd);
- int neR = GetRValue(crEnd);
- if(nSegments > pRect->Width())
- nSegments = pRect->Width();
- int nDiffR = (neR - nR);
- int nDiffG = (neG - nG);
- int nDiffB = (neB - nB);
- int ndR = 256 * (nDiffR) / (max(nSegments,1));
- int ndG = 256 * (nDiffG) / (max(nSegments,1));
- int ndB = 256 * (nDiffB) / (max(nSegments,1));
- nR *= 256;
- nG *= 256;
- nB *= 256;
- neR *= 256;
- neG *= 256;
- neB *= 256;
- int nCX = pRect->Width() / max(nSegments,1), nLeft = pRect->left, nRight;
- pDC->SelectStockObject(NULL_PEN);
- for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
- {
- // Use special code for the last segment to avoid any problems
- // with integer division.
- if (i == (nSegments - 1))
- nRight = pRect->right;
- else
- nRight = nLeft + nCX;
- cr = RGB(nR / 256, nG / 256, nB / 256);
- {
- CBrush br(cr);
- CBrush* pbrOld = pDC->SelectObject(&br);
- pDC->Rectangle(nLeft, pRect->top, nRight + 1, pRect->bottom);
- pDC->SelectObject(pbrOld);
- }
- // Reset the left side of the drawing rectangle.
- nLeft = nRight;
- }
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetFont
- //
- // Description: Sets font with LOGFONT structure
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 02072002 1.6 Origin
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetFont(LOGFONT lf)
- {
- CopyMemory(&m_lf, &lf, sizeof(m_lf));
- ReconstructFont();
- UpdateSurface();
- return *this;
- }
- BOOL CLabel::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetMailLink
- //
- // Description: Sets the label so it becomes Mail enabled
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 02072002 1.6 Origin
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetMailLink(BOOL bEnable, BOOL bNotifyParent)
- {
- if (bEnable)
- m_Link = MailLink;
- else
- m_Link = LinkNone;
- m_bNotifyParent = bNotifyParent;
- if (m_Link != LinkNone)
- ModifyStyle(0,SS_NOTIFY);
- else
- ModifyStyle(SS_NOTIFY,0);
- return *this;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Function: CLabel::SetHyperLink
- //
- // Description: Sets the label so it becomes hyperlink enabled
- //
- // INPUTS:
- //
- // RETURNS:
- //
- // NOTES:
- //
- // MODIFICATIONS:
- //
- // Name Date Version Comments
- // NT ALMOND 02072002 1.6 Origin
- //////////////////////////////////////////////////////////////////////////
- CLabel& CLabel::SetHyperLink(const CString& sLink)
- {
- m_sLink = sLink;
- return *this;
- }
- /*************************************************************
- *add at : 2014-08-11 by唐太闲
- *describe: 设置背景透明,返回空画刷
- *************************************************************/
- HBRUSH CLabel::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
- {
- // TODO: 在此更改 DC 的任何属性
- // TODO: 如果不应调用父级的处理程序,则返回非 null 画笔
- //return NULL;
- pDC->SetBkMode(TRANSPARENT);
- return (HBRUSH)GetStockObject(NULL_BRUSH);
- }
|