求助 通过滑动条改变对话框颜色
大家帮帮我,一个作业研究了几天也没研究出来,要求映射WM_CTLCOLOR来做……我的思路是设几个int变量代表每种颜色的值关联滑块,通过滑块的滑动改变值,然后在OnCtrlColor函数里通过这三个值创建一个画刷,并返回来实现。但问什么不行啊,滑动滑块一点反映都没有。
void CDialog_Test_5Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default int nID = pScrollBar->GetDlgCtrlID(); if (nID == m_ctrR.GetDlgCtrlID()) { m_R = m_ctrR.GetPos(); } else if (nID == m_ctrG.GetDlgCtrlID()) { m_G = m_ctrG.GetPos(); } else if (nID == m_ctrB.GetDlgCtrlID()) { m_B = m_ctrB.GetPos(); } else return; color = RGB(m_R, m_G, m_B); CDialog::OnHScroll(nSBCode, nPos, pScrollBar); } HBRUSH CDialog_Test_5Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if (nCtlColor == CTLCOLOR_DLG) { m_brush.CreateSolidBrush(color); return (HBRUSH)m_brush;} // TODO: Return a different brush if the default is not desired return hbr; }