📄 mystatic.cpp
字号:
// MyStatic.cpp : implementation file
//
#include "stdafx.h"
#include "SalaryManagement.h"
#include "MyStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyStatic
CMyStatic::CMyStatic()
{
m_crText=RGB(0,0,0); //文字颜色
m_crFirst=RGB(0,0,0); //文字初始的颜色
m_crMouse=RGB(255,0,0); //鼠标移动后文字的颜色
m_hHandCur=AfxGetApp()->LoadCursor(IDC_HANDCUR);
m_bOver=FALSE; //判断鼠标是否移到了控件上
m_bMouseMove=TRUE; //判断是否相应鼠标移动的消息
m_transparent=FALSE;
m_isRedraw=TRUE;
m_pCtrl=NULL; //显示鼠标移动时信息提示的控件指针
m_nIDStringIn=0;//显示鼠标移动到该控件上时信息提示的字符串ID
m_nIDStringOut=0;//显示鼠标移出该控件上时信息提示的字符串ID
}
CMyStatic::~CMyStatic()
{
}
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//{{AFX_MSG_MAP(CMyStatic)
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
void CMyStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.SelectObject(&m_font);
dc.SetTextColor(m_crText);
//设置透明
if(!m_transparent)
dc.SetBkMode(TRANSPARENT);
if(m_isRedraw)
{
CRect rect;
GetClientRect(rect);
// InvalidateRect(&rect);
/**/ ///输出文字
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
CString strText;
this->GetWindowText(strText);
int nTextTop=rect.top+(rect.Height()-tm.tmHeight)/2;
if(strText.GetLength()>0)
{
dc.TextOut(0,nTextTop,strText);
}
}
}
//响应鼠标移动消息
void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bOver) // Cursor is currently over control
{
CRect rect;
GetClientRect(rect);
if (!rect.PtInRect(point))
{
m_bOver = FALSE;
///恢复原来的字体颜色
m_crText=m_crFirst;
RedrawWindow(); //重绘窗口
ReleaseCapture(); //释放鼠标控制权
if(m_pCtrl!=NULL)
{
CString str;
VERIFY(str.LoadString(m_nIDStringOut));
m_pCtrl->SetWindowText(str);
}
return;
}
}
else // Cursor has just moved over control
{
m_bOver = TRUE;
if(m_bMouseMove)
{
m_crText=m_crMouse; //更改字体颜色
::SetCursor(m_hHandCur); //更改鼠标为手型
if(m_pCtrl!=NULL)
{
CString str;
VERIFY(str.LoadString(m_nIDStringIn));
m_pCtrl->SetWindowText(str);
}
}
RedrawWindow(); //重绘窗口
SetCapture(); //获取鼠标控制权
}
CStatic::OnMouseMove(nFlags, point);
}
void CMyStatic::Init()
{
//设置逻辑字体
m_logFont.lfCharSet=DEFAULT_CHARSET;
m_logFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
m_logFont.lfEscapement=0;
strcpy(m_logFont.lfFaceName,"宋体");
m_logFont.lfHeight=14;
m_logFont.lfItalic=false;
m_logFont.lfOrientation=0;
m_logFont.lfOutPrecision=OUT_DEFAULT_PRECIS;
m_logFont.lfPitchAndFamily=FF_SWISS;
m_logFont.lfQuality=DEFAULT_QUALITY;
m_logFont.lfStrikeOut=false;
m_logFont.lfUnderline=false;
m_logFont.lfWeight=1000;
m_font.CreateFontIndirect(&m_logFont);
}
//设置字体
void CMyStatic::SetFont(LOGFONT logfont)
{
m_font.CreateFontIndirect(&logfont);
Invalidate();
}
//判断是否响应鼠标移动,移动后字体的颜色
void CMyStatic::SetMouseMove( BOOL isRespond,COLORREF color)
{
m_crMouse=color;
m_bMouseMove=isRespond;
}
//设置文本颜色,初始时的颜色
void CMyStatic::SetTextColor(COLORREF crText)
{
m_crFirst=crText;
m_crText=crText;
}
//获取当前文本的字体
void CMyStatic::GetLogfont(LOGFONT &logfont)
{
logfont=m_logFont;
}
//设置文本不透明状态
void CMyStatic::RemoveTransparent()
{
m_transparent=TRUE;
}
//设置重绘时是否重新输出文本
void CMyStatic::SetRedraw(BOOL redraw)
{
m_isRedraw=redraw;
}
void CMyStatic::SetToopTip(CWnd* pCtrl, const UINT nIDStringIn, const UINT nIDStringOut)
{
this->m_pCtrl=pCtrl;
this->m_nIDStringIn=nIDStringIn;
this->m_nIDStringOut=nIDStringOut;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -