tags:

views:

385

answers:

1

If the parent form of a (text) static control has a pattern on its background, then the area around the static control is an ugly blotch of solid color. How can I paint the background of the static control with the same pattern that its parent window uses?

I've tried this,

SetClassLong(retval , GCL_HBRBACKGROUND, (LONG)stripes);

where retval was an HWND, pointing to the static control I just created,
and stripes is an HBRUSH created from a bitmap. I tried with this, too:

SetClassLongPtr(retval , GCLP_HBRBACKGROUND, (LONG)stripes);

Neither of them worked. Does anyone know how to change the background of a static control in C?

Update

I handled the WM_CTLCOLORSTATIC message, which worked to an extent--it filled up the empty space in all the labels with the pattern I wanted. But the color right behind the text was just white... How can I make the pattern fill up that space as well?

Nevermind, got it.
SetBkMode(hdc, TRANSPARENT);

+2  A: 

You can set the background color for a static control by handling the WM_CTLCOLOR message.

From the documentation

If an application processes this message, it returns a handle to a brush. The system uses the brush to paint the background of the control.

The message also passes a pointer to the display context that you can use.

Brian R. Bondy
You mean WM_CTLCOLORSTATIC. WM_CTLCOLOR is used in 16-bit applications (perhaps it still works for 32-bit apps ... i don't know.)
Michael
I use it in newer Win32 applications. Compiled as both 32bit and 64bit. Don't think what the program is compiled as makes any difference though.
Brian R. Bondy
I just used WM_CTLCOLORSTATIC, it works fine
Carson Myers
Cool, I guess both work.
Brian R. Bondy