I found some sample code like below, for trying to customize a scrollbar color:
HBRUSH CMainFrame::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFrameWnd::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_SCROLLBAR)
return m_brColor;
return hbr;
}
I found that the following code does not work:
procedure TForm1.WMCTLColor(var msg: TWMCTLCOLOR); message WM_CTLCOLOR;
How can I do it in Delphi?
There’s no
WM_CTLCOLORmessage in the native api. Instead you can useCN_CTLCOLORSCROLLBARcontrol notification, which is send to child controls by the VCL in response to the API’sWM_CTLCOLORSCROLLBAR.Or, if you don’t want to derive a new control, provided the scrollbar is placed on the form: