📄 custbutton.cpp
字号:
// CustButton.cpp : implementation file
//
#include "stdafx.h"
#include "VisualJava.h"
#include "CustButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustButton
CCustButton::CCustButton()
{
m_szpData = _T("This is how it will look");
m_nBkgrnd = RGB(0,0,0);
m_nFrgrnd = RGB(255,255,255);
m_nSize = 100;
m_pCurFont = NULL;
}
CCustButton::~CCustButton()
{
delete m_pCurFont;
m_pCurFont = NULL;
}
BEGIN_MESSAGE_MAP(CCustButton, CButton)
//{{AFX_MSG_MAP(CCustButton)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustButton message handlers
void CCustButton::PreSubclassWindow()
{
m_pCurFont = new CFont;
m_pCurFont->CreatePointFont(m_nSize,"Times New Roman",GetDC());
SetFont(m_pCurFont);
CButton::PreSubclassWindow();
}
void CCustButton::UpdateView(COLORREF bk, COLORREF fr, LPCTSTR szpFont,
int nSize)
{
if(szpFont != NULL)
{
delete m_pCurFont;
m_pCurFont = new CFont;
m_pCurFont->CreatePointFont(nSize,szpFont);
SetFont(m_pCurFont);
}
m_nBkgrnd = bk;
m_nFrgrnd = fr;
RedrawWindow();
}
void CCustButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
// Save these value to restore them when done drawing.
COLORREF crOldTextColor = dc.SetTextColor(m_nFrgrnd);
COLORREF crOldBkColor = dc.SetBkColor(m_nBkgrnd);
CBrush brush;
brush.CreateSolidBrush(m_nBkgrnd);
//CBrush pOldBrush = dc.SelectObject(&brush);
dc.FillRect(&lpDrawItemStruct->rcItem,&brush);
// Draw the text.
dc.DrawText(
m_szpData,
strlen(m_szpData),
&lpDrawItemStruct->rcItem,
DT_CENTER|DT_SINGLELINE|DT_VCENTER);
// Reset the background color and the text color back to their
// original values.
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
void CCustButton::UpdateFont(LPCTSTR szpFont)
{
delete m_pCurFont;
m_pCurFont = new CFont;
m_pCurFont->CreatePointFont(m_nSize,szpFont);
SetFont(m_pCurFont);
RedrawWindow();
}
void CCustButton::UpdateSize(int nSize)
{
m_nSize = nSize;
delete m_pCurFont;
m_pCurFont = new CFont;
m_pCurFont->CreatePointFont(m_nSize,m_szpFont);
SetFont(m_pCurFont);
RedrawWindow();
}
void CCustButton::UpdateBkgrnd(COLORREF nbkGrnd)
{
m_nBkgrnd = nbkGrnd; RedrawWindow();
}
void CCustButton::UpdateFrgrnd(COLORREF nfrGrnd)
{
m_nFrgrnd = nfrGrnd; RedrawWindow();
}
void CCustButton::UpdateBoth(COLORREF nfrGrnd,COLORREF nbkGrnd)
{
m_nFrgrnd = nfrGrnd;
m_nBkgrnd = nbkGrnd;
RedrawWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -