Changing button color in CToolBarCtrl
Paulo Soares -- psoares@ip.pt Thursday, July 04, 1996 vc++4.1, win95 I have a class derived from CToolBarCtrl where I want to change the = background color and the color of the buttons. The background color is easy to change with OnEraseBkgnd but I cannot = change the button colors with OnCtlColor. I've also tried doing this in = the parent but to no avail. Best Regards, Paulo Soares psoares@ip.pt
Don.Irvine@net-tel.co.uk Tuesday, July 09, 1996 [Mini-digest: 2 responses] > I have a class derived from CToolBarCtrl where I want to change the > background color and the color of the buttons. > The background color is easy to change with OnEraseBkgnd but I cannot change > the button colors with OnCtlColor. I've also tried doing this in the parent > but to no avail. CToolBar::LoadBitmap (and CToolBar::OnSysColorChange) call a function AfxLoadSysColorBitmap to modify the color table of the supplied toolbar bitmap to match the current system color scheme. You will need to modify this behaviour to change the background color of the button, but I think your stuck when you come to change the color of the button borders since these are drawn by the toolbar common control. You might want to look at the OLDBARS sample, which provides a complete MFC toolbar implementation. You will probably find this easier to customise. Don -----From: ktm@ormec.com This information applies to CButton controls. It may be of use for your problem as well. According to VC Books online help for "Button Color Messages", the WM_CTLCOLOR message has been replaced by control-color messages, so it seems that you should create a custom message handler for WM_CTLCOLORBTN instead. However, the KB article Q130952, also in VC++ Books online, states that this message is ignored, and system colors are always used for command buttons. So, to change the background color, you need to make the button an owner-drawn button. (overriding CButton::OnDraw) KB article Q64328 (on the MSDN CD) points to an example program of a (non-MFC) owner-drawn button at: ftp://ftp.microsoft.com/SOFTLIB/MSLFILES/ODBUTTON.EXE Best of luck, Katy ---- Katy Mulvey ktm@ormec.com Software Development Engineer ORMEC Systems 19 Linden Park; Rochester, NY 14625
| Вернуться в корень Архива |