Process wm_ctlcolor messages
Hbrush caboutdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
{
Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );
If (nctlcolor = ctlcolor_static)
{
PDC-> setbkmode (transparent );
Return m_backhbrush;
}
Return HBr;
}
M_backhbrush is defined as a member variable of the hbrush type and initialized in oninitdialog:
M_backhbrush = createsolidbrush (RGB (0,255,255 ));
Void cxxxdlg: onbnclickedbtnchange (){
// Get window handle of your static control cstatic *
Pstatic = (cstatic *) (getdlgitem (idc_static_variety ));
// Init random generator srand (unsigned (Time (null )));
// Release hbrush Object last time: deleteobject (m_hbrmybk );
// Create new brush and text color m_hbrmybk
= Createsolidbrush (RGB (RAND ()
% 256, Rand ()
% 256, Rand ()
% 256); m_crlmytext
= RGB (RAND ()
% 256, Rand ()
% 256, Rand ()
(% 256 );
// Force to repaint your static control pstatic-> invalidate (true);} hbrush
Cxxxdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor) {hbrush HBr
= Cdialog: onctlcolor (PDC, pwnd, nctlcolor );
// If your static control...
If (pwnd-> getdlgctrlid ()
==Idc_static_variety) {PDC-> setbkmode (transparent); PDC-> settextcolor (m_crlmytext );
HBr = m_hbrmybk ;}
Return HBr ;}