📄 zstatic.cpp
字号:
////////////////////////////////////////////////////////////
// 文件名: CZStatic.cpp
// 功能: 实现Static控件的字体属性改变
// 创建日期:2001-10-30
// 修改日期:2001-1--30
/////////////////////////////////////////////////////////////
// ZStatic.cpp : implementation file
//
#include "stdafx.h"
#include "PTChannel.h"
#include "ZStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZStatic
CZStatic::CZStatic()
{
//字体的颜色
m_Color=RGB(0,0,0);
//字体的大小
m_FontSize=12;
//字体的名称
strcpy(m_szFontName,"宋体");
//初始化字体属性
m_Font.CreateFont(12,0, 0, 0,
FW_NORMAL,
0, 0, 0, 0,
0, 0, 0, 0,
"宋体");
}
CZStatic::~CZStatic()
{
}
BEGIN_MESSAGE_MAP(CZStatic, CStatic)
//{{AFX_MSG_MAP(CZStatic)
ON_WM_PAINT()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZStatic message handlers
void CZStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
//获取窗口大小坐标
GetWindowRect(&rect);
//窗口化坐标
ScreenToClient(&rect);
dc.SetBkMode(OPAQUE);
dc.FillSolidRect(&rect,GetSysColor(COLOR_BTNFACE));
//设置字体颜色
dc.SetTextColor(m_Color);
//选择字体
CFont* pOldFont=dc.SelectObject(&m_Font);
dc.SetBkMode(TRANSPARENT);
dc.TextOut(0,0,m_Text);
dc.SelectObject(pOldFont);
// Do not call CStatic::OnPaint() for painting messages
}
//设置字体的大小
void CZStatic::SetFontSize(int nSize)
{
m_Font.DeleteObject();
m_Font.CreateFont(nSize,0, 0, 0,
FW_NORMAL,
0, 0, 0, 0,
0, 0, 0, 0,
m_szFontName);
Invalidate();
}
//设置字体名称
void CZStatic::SetFontName(LPCTSTR szFontName)
{
m_Font.DeleteObject();
m_Font.CreateFont(m_FontSize,0, 0, 0,
FW_NORMAL,
0, 0, 0, 0,
0, 0, 0, 0,
szFontName);
Invalidate();
}
//设置字体颜色
void CZStatic::SetFontColor(COLORREF fColor)
{
m_Color=fColor;
}
//设置标题文本
void CZStatic::SetText(LPCTSTR szText)
{
m_Text=szText;
Invalidate();
}
int CZStatic::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;
// 获取文本标题
GetWindowText(m_Text);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -