1

We have some C++ Win32 code that applies a background colour to certain controls by responding to the WM_CTLCOLOR... messages.

This works fine when Windows UX theming is not in operation.

Under Windows 7 with the default theme, comboboxes with CBS_DROPDOWNLIST style just display with the theme's grey background. CBS_DROPDOWN comboboxes respond correctly to the background colour change with the theme enabled.

I know I could remove the theme for the affected controls, but this makes them look odd.

Anyone have any idea of the official way to change the background color of individual themed controls now that MS seem to have broken the WM_CTLCOLOR... stuff.

Thanks JF

J Francis
  • 1,358
  • 9
  • 15
  • 1
    Just set the CBS_OWNERDRAWFIXED style flag. That will instantly kill the themed look, you'll get the old pre-Vista style. Your users might find that a bit grating, ymmv. – Hans Passant Apr 05 '12 at 16:38
  • 1
    Generally speaking, it's not a great idea to try to customize the colors of themed controls because you don't know what colors are in the theme, so you have no way of knowing whether you accidentally set the colors to "gray on gray" or something like that. – Raymond Chen Apr 05 '12 at 17:26

2 Answers2

1

You might check to see if you can accomplish what you want with NM_CUSTOMDRAW notifications. Those are sent to the parent (like WM_CTLCOLOR... messages). Some controls work better than others with these notifications. You don't always get all the notifications you'd expect.

The other option would be to subclass the control and override WM_PAINT. That would be a lot of work, but it's do-able. There is documentation on painting with the themes.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
0

If you want to change the color for themed controls you need to custom draw it using the theme API. That's a pretty tricky task that is essentially undocumented. Good luck!

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490