chenluhua1980
2026-01-10 9198ac12e4e2ff64a2cf65c32d576f02d54c346a
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// CPjPage1.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "CCjPageBase.h"
#include "afxdialogex.h"
 
 
// CPjPage1 对话框
 
IMPLEMENT_DYNAMIC(CCjPageBase, CDialogEx)
 
CCjPageBase::CCjPageBase(UINT nID, CWnd* pPage) : CDialogEx(nID, pPage)
{
    m_crBkgnd = RGB(255, 255, 255);
    m_crBkgndCached = CLR_INVALID;
    m_onContentChanged = nullptr;
    m_bContentChangedLock = FALSE;
    m_pContext = nullptr;
    m_nContextType = 0;
}
 
CCjPageBase::~CCjPageBase()
{
}
 
void CCjPageBase::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CCjPageBase, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_SIZE()
END_MESSAGE_MAP()
 
 
// CPjPage1 消息处理程序
 
void CCjPageBase::SetTitle(CString strTitle)
{
    SetDlgItemText(IDC_LABEL_TITLE, strTitle);
}
 
void CCjPageBase::SetContext(void* pContext, int type)
{
    m_pContext = pContext;
    m_nContextType = type;
    OnSetContext(pContext);
}
 
void* CCjPageBase::GetContext()
{
    return m_pContext;
}
 
void CCjPageBase::SetOnContentChanged(ONCONTENTCHANGED onContentChanged)
{
    m_onContentChanged = onContentChanged;
}
 
BOOL CCjPageBase::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    Resize();
 
 
    m_labelTitle.SubclassDlgItem(IDC_LABEL_TITLE, this);
    m_labelTitle.Setpadding(PADDING_LEFT, 0);
    m_labelTitle.Setpadding(PADDING_RIGHT, 0);
 
 ;
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
 
HBRUSH CCjPageBase::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 
    // 想给哪些控件改底色就把它们的类型写进来:
    const bool needCustomBg =
        (nCtlColor == CTLCOLOR_STATIC) ||
        (nCtlColor == CTLCOLOR_DLG) ||   // 对话框底色
        (nCtlColor == CTLCOLOR_BTN);        // 按钮(可选)
 
    if (needCustomBg)
    {
        // 若第一次创建,或颜色改变则重建
        if (m_brBkgnd.GetSafeHandle() == nullptr || m_crBkgndCached != m_crBkgnd)
        {
            if (m_brBkgnd.GetSafeHandle())
                m_brBkgnd.DeleteObject();
 
            m_brBkgnd.CreateSolidBrush(m_crBkgnd);
            m_crBkgndCached = m_crBkgnd;
        }
 
        // 文本前景/背景设置(仅影响文本绘制)
        pDC->SetBkColor(m_crBkgnd);
        pDC->SetTextColor(RGB(0, 0, 0));
        // 如需让静态文本透明叠在底色上,可用:
        // pDC->SetBkMode(TRANSPARENT);
 
        return (HBRUSH)m_brBkgnd; // 安全的隐式转换
    }
 
    // 其他控件类型沿用基类默认的刷子
    return hbr;
}
 
void CCjPageBase::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if (GetDlgItem(IDC_LABEL_TITLE) == nullptr) return;
    Resize();
}
 
void CCjPageBase::Resize()
{
    CWnd* pItem;
    CRect rcClient, rcItem;
    GetClientRect(&rcClient);
    pItem = GetDlgItem(IDC_LABEL_TITLE);
    pItem->GetWindowRect(&rcItem);
    pItem->MoveWindow(12, 8, rcClient.Width() - 24, rcItem.Height());
}
 
void CCjPageBase::ContentChanged(int code)
{
    if (!m_bContentChangedLock && m_onContentChanged != nullptr) {
        m_onContentChanged(this, code, m_pContext, m_nContextType);
    }
}