📄 checkbox.cpp
字号:
// CheckBox.cpp: implementation of the CCheckBox class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CheckBox.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCheckBox::CCheckBox()
{
m_bFocus = FALSE;
}
CCheckBox::~CCheckBox()
{
}
int CCheckBox::GetCheck()
{
return (m_bFocus?BST_CHECKED:BST_UNCHECKED);
}
void CCheckBox::SetCheck(int nState)
{
m_bFocus = (nState==BST_CHECKED);
RedrawWindow();
}
LRESULT CCheckBox::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// TODO : Add Code for message handler. Call DefWindowProc if necessary.
CPaintDC dcMem(m_hWnd);
CRect rect,rcClient;
GetClientRect(&rect);
rcClient = rect;
// draw focus frame
int nFrame = m_bFocus?BLACK_PEN:NULL_PEN;
HPEN hOldPen = dcMem.SelectStockPen(nFrame);
HBRUSH hBrush = dcMem.SelectStockBrush(WHITE_BRUSH);
dcMem.Rectangle(rect);
dcMem.SelectPen(hOldPen);
dcMem.SelectBrush(hBrush);
//draw button text
TCHAR szText[MAX_PATH];
int nSize = ::GetWindowText(m_hWnd,szText,MAX_PATH);
szText[nSize]='\0';
rect.right = rect.left + rect.Height();
CRect rcText(rect.right,rect.top+2,rcClient.right,rcClient.bottom);
dcMem.DrawText(szText,nSize,rcText,DT_CENTER);
//draw selected flag
rect -= CRect( 3,3,3,3);
dcMem.Ellipse(&rect);
rect -= CRect( 3,3,3,3);
if(m_bFocus)
{
CBrush br;
br.CreateSolidBrush(RGB(0,0,0));
HBRUSH hOldBrush = dcMem.SelectBrush(br.m_hBrush);
dcMem.Ellipse(&rect);
}
return 0;
}
LRESULT CCheckBox::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// TODO : Add Code for message handler. Call DefWindowProc if necessary.
m_bFocus = FALSE;
RedrawWindow();
return 0;
}
LRESULT CCheckBox::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// TODO : Add Code for message handler. Call DefWindowProc if necessary.
m_bFocus = TRUE;
RedrawWindow();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -