I am attempting to make the text colour and background of a group box control. I am using dialogs and Win32. To illustrate my problem I have created a project with the minimum code necessary to reproduce the issue.
If we take a dialog and put some sort of bitmap as the background, we can easily see the true colours of the group box control. By default without any overriding it will look like so:
I will attempt to set the text colour to white and the text background to transparent with the following code:
case WM_CTLCOLORSTATIC: {
HDC hDC = ( HDC )wParam;
SetTextColor( hDC, RGB( 255, 255, 255 ) );
SetBkMode( hDC, TRANSPARENT );
return ( INT_PTR )GetStockObject( HOLLOW_BRUSH );
}
I tested the look with and without visual styling enabled by changing the manifest with:
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
With visual styles, the dialog looks like so:
The background is changed to an unacceptable solid colour dependent on what the background of the dialog is. Also the text colour has failed to change. With visual styling disabled, the dialog looks like so:
The text colour has changed and the transparency has worked but the rectangle of the group box shows even where the text is.
I have uploaded the project here for anyone interested in testing with it.
I've read other similar questions on this site which seem to suggest perhaps this is not possible without subclassing or ownerdrawing. I don't mind subclassing but am checking there are not better ways to do it first. If the only way is subclassing, I would be happy for information on what should be overridden (probably WM_PAINT). I've found examples online of people creating their own group box controls but some seem to suffer from z-order issues. Therefore, with subclassing, would it be pertinent to handle WM_NCHITTEST?
Similarly, if I toggle the owner-draw style with SetWindowLong() and then subclass the control to get the WM_DRAWITEM messages, is there anything I should look out for? How should I deal with visual styles, etc.?