📄 czbutton.cpp
字号:
// CzButton.cpp : implementation file
//
#include "stdafx.h"
#include "tsq.h"
#include "CzButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCzButton
CCzButton::CCzButton()
{
m_Textbk=RGB(128,128,128);
}
CCzButton::~CCzButton()
{
}
BEGIN_MESSAGE_MAP(CCzButton, CButton)
//{{AFX_MSG_MAP(CCzButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCzButton message handlers
void CCzButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH;
// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CFont font;
VERIFY(font.CreateFont(
22, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
DEFAULT_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
PROOF_QUALITY ,// DEFAULT_QUALITY, // nQuality
VARIABLE_PITCH|FF_ROMAN,//DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"楷体_GB2312")); // lpszFacename
CFont* def_font = pDC->SelectObject(&font);
/*LOGBRUSH logBrush;
logBrush.lbStyle = BS_HATCHED;
logBrush.lbColor = RGB(0,200,0);
logBrush.lbHatch = HS_CROSS;*/
// Declare an uninitialized CBrush ...
//CBrush brush;
// ... and initialize it with the LOGBRUSH.
//brush.CreateBrushIndirect(&logBrush);
//brush.CreateSolidBrush(RGB(255,0,0));
//CBrush* pOldBrush = pDC->SelectObject(&brush);
// Draw the button frame.
//CRect rect;
//rect=lpDrawItemStruct->rcItem;
//pDC->RoundRect(rect.left, rect.top, rect.Width(), rect.Height(), 2, 2);
//pDC->DrawFrameControl(&lpDrawItemStruct->rcItem,DFC_BUTTON, uStyle);
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle);
//brush.DeleteObject();
//pDC->SelectObject(pOldBrush);
// Get the button's text.
CString strText;
GetWindowText(strText);
// Draw the button text using the text color red.
// COLORREF crOldColor;
// if(m_bLBtnDown)pDC->SetTextColor(RGB(255,0,0));
// else pDC->SetTextColor(RGB(0,255,0));
pDC->SetTextColor(m_Textbk);
//crOldColor= ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
// ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
pDC->SelectObject(def_font);
}
void CCzButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// m_bLBtnDown=TRUE;
CButton::OnLButtonDown(nFlags, point);
}
void CCzButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bLBtnDown=FALSE;
CButton::OnLButtonUp(nFlags, point);
}
void CCzButton::SetTxetBk(COLORREF rgb)
{
m_Textbk=rgb;
}
HBRUSH CCzButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
//if(nCtlColor==CTLCOLOR_EDIT)
//{ // pDC->SetBkMode(TRANSPARENT);
// pDC->SetBkColor(RGB(0,0,0));
// HBRUSH B = CreateSolidBrush(RGB(200,0,0));
// return (HBRUSH) B;
//}
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -