|
|
|
|
// LabelEx.cpp : implementation file
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "LabelEx.h"
|
|
|
|
|
#include "GlobalDefine.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
|
#undef THIS_FILE
|
|
|
|
|
static char THIS_FILE[] = __FILE__;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// CLabelEx
|
|
|
|
|
|
|
|
|
|
CLabelEx::CLabelEx()
|
|
|
|
|
{
|
|
|
|
|
m_bClicked=FALSE;
|
|
|
|
|
m_bOver=FALSE;
|
|
|
|
|
m_bUnderLine=FALSE;
|
|
|
|
|
m_bAutoUnderLine=FALSE;
|
|
|
|
|
m_bBorder=FALSE;
|
|
|
|
|
m_bHighLight=TRUE;
|
|
|
|
|
m_bBackUnderLine=FALSE;
|
|
|
|
|
|
|
|
|
|
m_crText=RGB(0,0,0);
|
|
|
|
|
m_crBorder=RGB(0,0,0);
|
|
|
|
|
m_crBG=RGB(255,255,255);
|
|
|
|
|
m_crUnderLine=RGB(0,0,255);
|
|
|
|
|
|
|
|
|
|
m_hHandCur=AfxGetApp()->LoadCursor(IDC_HAND);
|
|
|
|
|
|
|
|
|
|
SetTextColor(RGB_RED);
|
|
|
|
|
SetBkColor(RGB_GRAY);
|
|
|
|
|
|
|
|
|
|
m_CurBmpID = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLabelEx::~CLabelEx()
|
|
|
|
|
{
|
|
|
|
|
if(m_BGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_BGBm.DeleteObject();
|
|
|
|
|
if(m_MouseOverBGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_MouseOverBGBm.DeleteObject();
|
|
|
|
|
if(m_ClickedBGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_ClickedBGBm.DeleteObject();
|
|
|
|
|
if(m_LabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_LabelBm.DeleteObject();
|
|
|
|
|
if(m_MouseOverLabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_MouseOverLabelBm.DeleteObject();
|
|
|
|
|
if(m_ClickedLabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_ClickedLabelBm.DeleteObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CLabelEx, CStatic)
|
|
|
|
|
//{{AFX_MSG_MAP(CLabelEx)
|
|
|
|
|
ON_WM_PAINT()
|
|
|
|
|
ON_WM_MOUSEMOVE()
|
|
|
|
|
ON_WM_LBUTTONDOWN()
|
|
|
|
|
//}}AFX_MSG_MAP
|
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// CLabelEx message handlers
|
|
|
|
|
|
|
|
|
|
void CLabelEx::OnPaint()
|
|
|
|
|
{
|
|
|
|
|
CPaintDC dc(this); // device context for painting
|
|
|
|
|
dc.SetTextColor(m_crText);
|
|
|
|
|
dc.SetBkMode(TRANSPARENT);
|
|
|
|
|
dc.SelectObject(this->GetFont());
|
|
|
|
|
///<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CRect rect;
|
|
|
|
|
CDC MemDC;
|
|
|
|
|
CPen BorderPen,*pOldPen,UnderLinePen;
|
|
|
|
|
CBrush BGBrush,*pOldBrush;
|
|
|
|
|
BITMAP bm;
|
|
|
|
|
|
|
|
|
|
this->GetClientRect(&rect);
|
|
|
|
|
|
|
|
|
|
MemDC.CreateCompatibleDC(&dc);
|
|
|
|
|
MemDC.SetMapMode(dc.GetMapMode());
|
|
|
|
|
|
|
|
|
|
///<2F><><EFBFBD>߿<EFBFBD>
|
|
|
|
|
if(m_bBorder)
|
|
|
|
|
{
|
|
|
|
|
BorderPen.CreatePen(PS_SOLID,1,m_crBorder);
|
|
|
|
|
BGBrush.CreateSolidBrush(m_crBG);
|
|
|
|
|
|
|
|
|
|
pOldPen=dc.SelectObject(&BorderPen);
|
|
|
|
|
pOldBrush=dc.SelectObject(&BGBrush);
|
|
|
|
|
|
|
|
|
|
dc.Rectangle(&rect);
|
|
|
|
|
|
|
|
|
|
dc.SelectObject(pOldPen);
|
|
|
|
|
dc.SelectObject(pOldBrush);
|
|
|
|
|
|
|
|
|
|
rect.DeflateRect(1,1);
|
|
|
|
|
}
|
|
|
|
|
///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ
|
|
|
|
|
if(m_bClicked && m_ClickedBGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
{
|
|
|
|
|
MemDC.SelectObject(m_ClickedBGBm);
|
|
|
|
|
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),
|
|
|
|
|
&MemDC,0,0,SRCCOPY);
|
|
|
|
|
}
|
|
|
|
|
else if(m_bOver && m_MouseOverBGBm.GetSafeHandle()!=NULL)//<2F><><EFBFBD>꾭<EFBFBD><EABEAD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
{
|
|
|
|
|
MemDC.SelectObject(m_MouseOverBGBm);
|
|
|
|
|
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),
|
|
|
|
|
&MemDC,0,0,SRCCOPY);
|
|
|
|
|
}
|
|
|
|
|
else if(m_BGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
{
|
|
|
|
|
MemDC.SelectObject(m_BGBm);
|
|
|
|
|
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),
|
|
|
|
|
&MemDC,0,0,SRCCOPY);
|
|
|
|
|
}
|
|
|
|
|
///<2F><><EFBFBD><EFBFBD>ǩͼƬ
|
|
|
|
|
if(m_bClicked && m_ClickedLabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
{
|
|
|
|
|
m_ClickedLabelBm.GetBitmap(&bm);
|
|
|
|
|
double fScal=bm.bmWidth*1.0/bm.bmHeight;
|
|
|
|
|
MemDC.SelectObject(m_ClickedLabelBm);
|
|
|
|
|
dc.StretchBlt(rect.left,rect.top,int(rect.Height()*fScal),rect.Height(),
|
|
|
|
|
&MemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
|
|
|
|
|
}
|
|
|
|
|
else if(m_bOver && m_MouseOverLabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
{
|
|
|
|
|
m_MouseOverLabelBm.GetBitmap(&bm);
|
|
|
|
|
double fScal=bm.bmWidth*1.0/bm.bmHeight;
|
|
|
|
|
MemDC.SelectObject(m_MouseOverLabelBm);
|
|
|
|
|
dc.StretchBlt(rect.left,rect.top,int(rect.Height()*fScal),rect.Height(),
|
|
|
|
|
&MemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
|
|
|
|
|
}
|
|
|
|
|
else if(m_LabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
{
|
|
|
|
|
m_LabelBm.GetBitmap(&bm);
|
|
|
|
|
double fScal=bm.bmWidth*1.0/bm.bmHeight;
|
|
|
|
|
MemDC.SelectObject(m_LabelBm);
|
|
|
|
|
dc.StretchBlt(rect.left,rect.top,int(rect.Height()*fScal),rect.Height(),
|
|
|
|
|
&MemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
TEXTMETRIC tm;
|
|
|
|
|
dc.GetTextMetrics(&tm);
|
|
|
|
|
CString strText1 = m_CurText1;
|
|
|
|
|
CString strText2 = m_CurText2;
|
|
|
|
|
if(strText1.GetLength()>0)
|
|
|
|
|
{
|
|
|
|
|
CRect TextRect = rect;
|
|
|
|
|
int AdjustPos = -8;
|
|
|
|
|
TextRect.bottom += AdjustPos;
|
|
|
|
|
TextRect.top += AdjustPos;
|
|
|
|
|
dc.DrawText(strText1, -1, &TextRect, DT_SINGLELINE| DT_VCENTER | DT_CENTER);
|
|
|
|
|
}
|
|
|
|
|
if(strText2.GetLength()>0)
|
|
|
|
|
{
|
|
|
|
|
CRect TextRect = rect;
|
|
|
|
|
int AdjustPos = 12;
|
|
|
|
|
TextRect.bottom += AdjustPos;
|
|
|
|
|
TextRect.top += AdjustPos;
|
|
|
|
|
dc.DrawText(strText2, -1, &TextRect, DT_SINGLELINE| DT_VCENTER | DT_CENTER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::PreSubclassWindow()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Add your specialized code here and/or call the base class
|
|
|
|
|
DWORD dwStyle = GetStyle();
|
|
|
|
|
::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
|
|
|
|
|
|
|
|
|
|
SetFont(GetParent()->GetFont());
|
|
|
|
|
CStatic::PreSubclassWindow();
|
|
|
|
|
}
|
|
|
|
|
void CLabelEx::SetTextColor(COLORREF crText)
|
|
|
|
|
{
|
|
|
|
|
m_crText=crText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetUnderLine(BOOL bUnderLine, COLORREF crUnderLine)
|
|
|
|
|
{
|
|
|
|
|
m_bUnderLine=bUnderLine;
|
|
|
|
|
m_crUnderLine=crUnderLine;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetBorder(BOOL bBorder, COLORREF crBorder)
|
|
|
|
|
{
|
|
|
|
|
m_bBorder=bBorder;
|
|
|
|
|
m_crBorder=crBorder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetBkColor(COLORREF crBkColor)
|
|
|
|
|
{
|
|
|
|
|
m_crBG=crBkColor;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::EnableAutoUnderLine(BOOL bAutoUnderLine)
|
|
|
|
|
{
|
|
|
|
|
m_bAutoUnderLine=bAutoUnderLine;
|
|
|
|
|
if(m_bAutoUnderLine) ///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>»<EFBFBD><C2BB><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
m_bBackUnderLine=m_bUnderLine;//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD>»<EFBFBD><C2BB>ߵ<EFBFBD>״̬
|
|
|
|
|
m_bUnderLine=FALSE;
|
|
|
|
|
}
|
|
|
|
|
else ///ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>»<EFBFBD><C2BB><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
m_bUnderLine=m_bBackUnderLine;//<2F>ظ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD>»<EFBFBD><C2BB>ߵ<EFBFBD>״̬
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::RedrawWindow()
|
|
|
|
|
{
|
|
|
|
|
CStatic::RedrawWindow();
|
|
|
|
|
//RECT rect;
|
|
|
|
|
//this->GetWindowRect(&rect);
|
|
|
|
|
//GetParent()->ScreenToClient(&rect);
|
|
|
|
|
//GetParent()->InvalidateRect(&rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetBGBitmap(UINT ID)
|
|
|
|
|
{
|
|
|
|
|
if(m_BGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_BGBm.DeleteObject();
|
|
|
|
|
m_BGBm.LoadBitmap(ID);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetMouseOverBGBitmap(UINT ID)
|
|
|
|
|
{
|
|
|
|
|
if(m_MouseOverBGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_MouseOverBGBm.DeleteObject();
|
|
|
|
|
m_MouseOverBGBm.LoadBitmap(ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetClickedBGBitmap(UINT ID)
|
|
|
|
|
{
|
|
|
|
|
if(m_ClickedBGBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_ClickedBGBm.DeleteObject();
|
|
|
|
|
m_ClickedBGBm.LoadBitmap(ID);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetLabelBitmap(UINT ID)
|
|
|
|
|
{
|
|
|
|
|
if(m_LabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_LabelBm.DeleteObject();
|
|
|
|
|
m_LabelBm.LoadBitmap(ID);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void CLabelEx::OnLButtonDown(UINT nFlags, CPoint point)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Add your message handler code here and/or call default
|
|
|
|
|
m_bClicked=!m_bClicked;
|
|
|
|
|
RedrawWindow();
|
|
|
|
|
CStatic::OnLButtonDown(nFlags, point);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetMouseOverLabelBitmap(UINT ID)
|
|
|
|
|
{
|
|
|
|
|
if(m_MouseOverLabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_MouseOverLabelBm.DeleteObject();
|
|
|
|
|
m_MouseOverLabelBm.LoadBitmap(ID);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLabelEx::SetClickedLabelBitmap(UINT ID)
|
|
|
|
|
{
|
|
|
|
|
if(m_ClickedLabelBm.GetSafeHandle()!=NULL)
|
|
|
|
|
m_ClickedLabelBm.DeleteObject();
|
|
|
|
|
m_ClickedLabelBm.LoadBitmap(ID);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
///<2F>Զ<EFBFBD><D4B6><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
void CLabelEx::EnableHighLight(BOOL bHighLight)
|
|
|
|
|
{
|
|
|
|
|
m_bHighLight=bHighLight;
|
|
|
|
|
}
|
|
|
|
|
void CLabelEx::SetLabelInfo(UINT ID,CString Text1,CString Text2)
|
|
|
|
|
{
|
|
|
|
|
if(m_CurBmpID!=ID || Text1 != m_CurText1|| Text2 != m_CurText2)
|
|
|
|
|
{
|
|
|
|
|
m_CurText1 = Text1;
|
|
|
|
|
m_CurText2 = Text2;
|
|
|
|
|
m_CurBmpID = ID;
|
|
|
|
|
SetLabelBitmap(ID);
|
|
|
|
|
RedrawWindow();//<2F>ػ<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|