Transparent Text in a Windows Dialogue Box
IN C++
A surprisingly difficult problem came up for me the other day while I was trying to program a windows dialogue box. I had set a bitmap image to the background of the dialogue box and wanted to place some text over top of it. When I tried to do this, however, my text suddenly had a background colour behind it and looked seriously ugly. The solution was hard to find but quite simple.
As it turns out, you want to trap the WM_CTLCOLORSTATIC message in your dlgProc method and return the NULL_BRUSH. Doing this allows you to remove the ugly background colour of your text.
BOOL CALLBACK dlgProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch(msg)
{
case WM_CTLCOLORSTATIC:
{
SetBkMode((HDC)wp, TRANSPARENT);
SetTextColor((HDC)wp, RGB(255, 255, 255));
return (BOOL)GetStockObject(NULL_BRUSH);
}
break;
}
I hope this helps anyone who has the same problem.