title: Creating a text label with a transparent background using WinAPI
body: <p>Is it possible to create a label with a transparent background within a window using only WinAPI commands?</p>
  
  <p>I am trying to add an image to a Dialog window that will serve as a background image and then display text upon that image. Everything I have tried so far shows the text label on top of the background image with a grey rectangle drawn around it.</p>
  
  <p>This is an example of my code so far (showing the entire message handler for the dialog):</p>
  
  <pre><code>INT_PTR CALLBACK OfferWindowProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  {       
      HWND hWndBackground;
      HWND hWndLabel;
      HBRUSH hLabelBackColour = NULL;
        HFONT hfFont;
        HWND hWndTitleLabel;
      HDC hdcStatic = NULL;
  
      UNREFERENCED_PARAMETER(lParam);
      switch (message)
      {
      case WM_INITDIALOG:             
  
          //Load the background image
          HANDLE hBitmap;
          hBitmap = LoadImage(NULL, L"C:\\Users\\DavidHall\\Documents\\bg.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
          if (hBitmap != NULL)
          {
              hWndBackground = CreateWindow(L"STATIC", L"image box", WS_CHILD | WS_VISIBLE | SS_BITMAP, 0, 0, 100, 100, hDlg, (HMENU) 2000, NULL, NULL);          
              SendMessage(hWndBackground, STM_SETIMAGE, IMAGE_BITMAP, LPARAM(hBitmap));
          }           
  
          // Create the label using CreateWindowEx
          hfFont = CreateFont(20, 0, 0, 0, fontWeight, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
              DEFAULT_PITCH, L"Verdana");
  
          hWndTitleLabel = CreateWindowEx( WS_EX_TRANSPARENT, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT | WS_SYSMENU , xPos, yPos, width, height, hwnd, (HMENU) id, hInst, NULL);           
  
          SendMessage(hWndTitleLabel, WM_SETTEXT, NULL, (LPARAM) labelText.c_str());
  
          SendMessage(hWndTitleLabel, WM_SETFONT, (WPARAM)hfFont, NULL);  
  
          return (INT_PTR)TRUE;   
  
      case WM_CLOSE:
          EndDialog(hDlg, LOWORD(wParam));    
  
          // Delete the brush - is that correct?
          DeleteObject(hLabelBackColour);
          return (INT_PTR)TRUE;
  
      case WM_COMMAND:
          if (LOWORD(wParam) == IDCANCEL)
          {
              EndDialog(hDlg, LOWORD(wParam));
              return (INT_PTR)TRUE;
          }
          break;
      default:
          break;
      }
      return (INT_PTR)FALSE;
  }
  </code></pre>
  
  <p>I've tried various combinations of things including:</p>
  
  <ul>
  <li><code>SetLayeredWindowAttributes</code></li>
  <li><code>SetBkMode(hdc, TRANSPARENT)</code></li>
  <li>Handling the <code>WM_CTLCOLORSTATIC</code> message</li>
  </ul>