在onButton()函数里我想重载 OnCtrlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 函数.
在一般就可以直接写 该函数名等,可想OnCtrlColor函数后面还有CDC,CWnd,nCtlColor
三个值不知这样写? 有位朋友教我用WM_CTLCOLOR消息但我不知具体代码这写?
在一般就可以直接写 该函数名等,可想OnCtrlColor函数后面还有CDC,CWnd,nCtlColor
三个值不知这样写? 有位朋友教我用WM_CTLCOLOR消息但我不知具体代码这写?
WM_CTLCOLOR在Button的窗口中处理,但对button不管用!
OnCtrlColor (...)函数 来重新改变STATIC的颜色
HBRUSH CBackstaticDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDC_STATIC1)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0)); // Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
// Return handle to our CBrush object
hbr = m_brush;
}
BOOL CBackstaticDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_brush.CreateSolidBrush(RGB(0,255,255));
return TRUE; // return TRUE unless you set the focus to a control
}
只要我在onButton()里重新给m_brush.CreateSolidBrush(RGB(0,255,0));
在重载 OnCtrlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 不是ok吗?
void CXXXDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_bButtonClicked=TRUE;
Invalidate();
}
HBRUSH CXXXDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_STATIC&&m_bButtonClicked)
{
pDC->SetBkColor(RGB(0,255,255));
CBrush Brush(RGB(0,255,255));
hbr=(HBRUSH)(Brush.GetSafeHandle());
}
// TODO: Return a different brush if the default is not desired
return hbr;
}