Hi there!

I'm creating STATIC windows invoking CreateWindow. The background of my window is NOT grey.

My 'hbrBackground' member of WNDCLASSEX is a handle to a brush I've previously created with CreatePatternBrush. It works fine, the window is painted using my bmp.

The problem is the background of the static windows which is grey.

Is it possible to make it transparent?

Thanks

_OuzO_
Posted on 2003-02-18 11:43:04 by _OuzO_
You could use the SetBkMode function and set the background to TRANSPARENT. Process the WM_CTLCOLORSTATIC, see the win32.hlp for details on the message.

From the Win32.hlp:
The SetBkMode function sets the background mix mode of the specified device context. The background mix mode is used with text, hatched brushes, and pen styles that are not solid lines.

int SetBkMode(

HDC hdc, // handle of device context
int iBkMode // flag specifying background mode
);


Parameters
hdc - Identifies the device context.
iBkMode - Specifies the background mode. This parameter can be either of the following values:

Value Description
OPAQUE Background is filled with the current background color before the text, hatched brush, or pen is drawn.
TRANSPARENT Background remains untouched.


Return Values
If the function succeeds, the return value specifies the previous background mode.
If the function fails, the return value is zero.

Remarks
The SetBkMode function affects the line styles for lines drawn using a pen created by the CreatePen function. SetBkMode does not affect lines drawn using a pen created by the ExtCreatePen function.
The iBkMode parameter can also be set to driver-specific values. GDI passes such values to the device driver and otherwise ignores them.
Posted on 2003-02-18 13:57:40 by scientica
i think all you gotta do is process wm_ctlcolorstatic and return a null_brush... search the board for null_brush its been talked about alot
Posted on 2003-02-18 20:42:12 by BubbaFate
i think all you gotta do is process wm_ctlcolorstatic and return a null_brush...
Nope, that is for the background colour, it has nothing to do with transparency. As at Win2K (dunno if it has changed with XP), STATICs have two background modes: TRANSPARENT and OPAQUE, as mentioned in the first reply these are set with a call to SetBkMode.
Posted on 2003-02-19 04:15:23 by sluggy
You gotta do both... the background of the static control is made transparent by returning a NULL_BRUSH which effectively means dont do any painting to the static controls background. There is another background that is related to the actual text on the static and you make that background transparent with SetBkMode. So effectively the code should look something like this...

.elseif uMsg == WM_CTLCOLORSTATIC

invoke SetBkMode, wParam, TRANSPARENT [color=green]; Set text background transparent[/color]
invoke GetStockObject, NULL_BRUSH [color=green]; Get NULL_BRUSH handle[/color]
ret [color=green]; Return the handle to set statics background transparent[/color]
Posted on 2003-02-19 15:10:54 by BubbaFate
BubbaFate,
my apologies, you are entirely correct. SetBkMode is used to set the background of the font, not the static itself. Next time i will think a little more before whipping out quick replies :grin:
Posted on 2003-02-20 05:06:06 by sluggy
Thank you all guys. This forum is a great place where to learn.

_OuzO_
Posted on 2003-02-21 02:41:34 by _OuzO_