Transparent Win32 controls for all versions of Windows

I am working on a Win32 graphical application using the simple Win32 API (without MFC or .NET). The problem I am facing is that the controls look transparent. I came up with a method that works for most things, in Windows Vista + I do this in WndProc:

case WM_CTLCOLORSTATIC:
{
    SetBkMode((HDC)wParam, TRANSPARENT);
    return (INT_PTR)::GetStockObject(NULL_PEN);
}
break;

In Windows XP, I do this in WndProc:

case WM_CTLCOLORSTATIC:
{
    HBRUSH hbr = (HBRUSH)DefWindowProc(hDlg, message, wParam, lParam);
    ::DeleteObject(hbr);
    SetBkMode((HDC)wParam, TRANSPARENT);
    return (LRESULT)(HBRUSH)(COLOR_WINDOW);
}

Now this works for most controls, however I get a transparent background on the label at the top of the group box control, which draws a line in the group box through text. I started working on the case only for group boxes, but I am sure that this is a problem that must have been resolved earlier, and I do not want to reinvent the wheel again.

?

, J

+5
1

, , :

  • . "" .
  • , , .
  • "" , , , , Windows.

"" , . . CreatePatternBrush .

DialogProc , , , :

  // _hwnd is the dialogs handle
  // _hbrSkin is a pattern brush handle
  HWND hwndCtl;
  POINT pt;
  HDC hdc;
case WM_CTLCOLORDLG:
  return (INT_PTR)_hbrSkin;
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
  hdc = (HDC)wParam;
  SetBkMode(hdc,TRANSPARENT); // Ensure that "static" text doesn't use a solid fill
  pt.x = 0; pt.y = 0;
  MapWindowPoints(hwndCtl,_hwnd,&pt,1);
  SetBrushOrgEx(hdc,-pt.x,-pt.y,NULL);
  return (INT_PTR)_hbrSkin;

, , , "" . :

  • .
  • WS_EX_COMPOSITED , Windows NT 6 DWM , Vista.
  • WS_CLIPCHILDREN / WS_CLIPSIBLINGS - , .
  • , WM_PRINTCLIENT, , blitting backbuffer . WM_PRINTCLIENT.
+6

All Articles