I wanted to change the background color of the check box, so I made the following class.
// custom_button.h
#pragma once
class CCustomButton : public CButton
{
DECLARE_DYNAMIC(CCustomButton)
public:
CBrush brush_ = RGB(0, 255, 0);
protected:
DECLARE_MESSAGE_MAP()
afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
};
// custom_button.cpp
#include "pch.h"
#include "custom_button.h"
IMPLEMENT_DYNAMIC(CCustomButton, CButton)
BEGIN_MESSAGE_MAP(CCustomButton, CButton)
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
HBRUSH CCustomButton::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
return brush_;
}
When this control is put into the dialog, it works fine, but when it is put into the view, it does not work even though the CCustomButton::CtlColor is called.
void CTestAppView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
button.Create(_T("Test"), WS_CHILD | WS_VISIBLE | WS_BORDER | BS_AUTOCHECKBOX, CRect(10, 10, 70, 60), this, IDC_STATIC);
}
BOOL CTestDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
button.Create(_T("Test"), WS_CHILD | WS_VISIBLE | WS_BORDER | BS_AUTOCHECKBOX, CRect(10, 10, 70, 60), this, IDC_STATIC);
return TRUE;
}

Why are the results different?