Home > Software engineering >  MFC OnCtlColor why can't change some controls the background color?
MFC OnCtlColor why can't change some controls the background color?

Time:09-19

Said the Internet to many articles, with OnCtlColor can change ListControl controls the background color, I have tried under vc + + 6.0 and VS2013, don't work, the code is as follows:


HBRUSH CListControlColorDlg: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
HBRUSH gets=CDialog: : OnCtlColor (pDC, pWnd, nCtlColor);

//TODO: Change any attributes of the DC here
If (nCtlColor==CTLCOLOR_LISTBOX)
{
Return m_brush;
}
//TODO: the Return of a company's brush if the default is not desired
Return gets;
}

And change the if statement to the if (pWnd - & gt; GetDlgCtrlID ()==IDC_LIST_TEST) also not line, change the if statement to the if (nCtlColor==CTLCOLOR_BTN) of the button control doesn't work, don't know why, which ace to give directions, thank you!

CodePudding user response:

Listctrl SetBkColor try

CodePudding user response:

It is said that a new button without CTLCOLOR_BTN news

CodePudding user response:

Is really can change, but if your character set is a Unicode cannot change
Interface style problem, it is because the Unicode mode is mainly interface style problem, just the default character set mode to control the interface style
Only under the XP style CTLCOLOR_LISTBOX background will change
Unicode mode for change with system interface style
  • Related