LAPTOP-SNT8I5JK\Boounion
2025-09-11 71766e0946eaaf4473377a7943d6bc61da94a604
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "stdafx.h"
#include "CCustomCheckBox.h"
 
 
CCustomCheckBox::CCustomCheckBox()
    : m_bgColor(RGB(255, 255, 255)), m_textColor(RGB(0, 0, 0))
{
    m_brush.CreateSolidBrush(m_bgColor);
}
 
CCustomCheckBox::~CCustomCheckBox()
{
 
}
 
void CCustomCheckBox::SetBackgroundColor(COLORREF color)
{
    m_bgColor = color;
    if (m_brush.GetSafeHandle())
        m_brush.DeleteObject();
    m_brush.CreateSolidBrush(m_bgColor);
    Invalidate();
}
 
void CCustomCheckBox::SetTextColor(COLORREF color)
{
    m_textColor = color;
    Invalidate();
}
 
void CCustomCheckBox::SetNotifyHwnd(HWND hWnd)
{
    m_hNotifyWnd = hWnd;
}
 
void CCustomCheckBox::OnClicked()
{
    BOOL bChecked = (GetCheck() == BST_CHECKED);
 
    // Äã¿ÉÒÔ¶¨Òå×Ô¼ºµÄ×Ô¶¨ÒåÏûÏ¢
    if (m_hNotifyWnd && ::IsWindow(m_hNotifyWnd)) {
        ::PostMessage(m_hNotifyWnd, WM_CHECKBOX_STATE_CHANGED, GetDlgCtrlID(), bChecked);
    }
}
 
BEGIN_MESSAGE_MAP(CCustomCheckBox, CButton)
    ON_WM_CTLCOLOR_REFLECT()
    ON_CONTROL_REFLECT(BN_CLICKED, &CCustomCheckBox::OnClicked)
END_MESSAGE_MAP()
 
HBRUSH CCustomCheckBox::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(m_textColor);
    return (HBRUSH)m_brush.GetSafeHandle();
}