Styles for "Static" windows

I am creating static text with the Win32 API. I've recently added a background to my parent window and I'd like to make the background for these child windows transparent. How can I do this?

Also, how can I change the font, text size or foreground color of the window?

This is how I am creating the static objects:
1
2
3
4
5
6
7
8
9
10
11
12
void StaticText::Create(string text, int Xpos, int Ypos, int Xsize, int Ysize, HWND parent, int ident)
{
    hwnd = CreateWindowEx(0,
	"Static", 
	text.c_str(), 
	WS_CHILD | WS_VISIBLE, 
	Xpos, Ypos, Xsize, Ysize, 
	parent, 
	(HMENU)ident, 
	NULL, 
	NULL);
}


Failed fix 1:
I've tried a few of the styles defined here:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb760773(v=vs.85).aspx

The closest I could find was SS_WHITERECT, but this turns the background AND foreground white.

Failed fix 2:
I managed to enable the window 7 styles by doing the following, but it didn't help with my transparency issues:

1
2
3
#pragma comment(linker,"/manifestdependency:\"type='win32' "\
    "name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' "\
    "publicKeyToken='6595b64144ccf1df' language='*'\"") 


Failed fix 3:
1
2
3
hwnd = CreateWindowEx(...
HDC hdc = GetDC(hwnd);
SetBkMode(hdc,TRANSPARENT);
No effect


Failed fix 4:
1
2
3
4
5
6
7
8
9
switch(msg)
{
    //...
    case WM_CTLCOLORSTATIC:
    {
	SetBkMode((HDC)wParam, TRANSPARENT);
	return (LRESULT)GetStockObject(NULL_BRUSH);
    }
}
This is so close.
The backgrounds become transparent.
But when I try to change the text, 
the old value isn't erased

<- If ln 6 is commented out, everything
   is okay except for the background of
   the space used up by text (it doesn't
   affect the whole object).
Last edited on
Topic archived. No new replies allowed.