title: transparency layered window white
body: <p>I'm trying to make a layered window with c++ win32 but I'm having a problem with the drawing or "collision" of it</p>
  
  <p>For reference the picture that I'm trying to display.</p>
  
  <p><img src="https://i.stack.imgur.com/8mXHs.png" alt="default"></p>
  
  <p>This is the basic creation of the window</p>
  
  <pre><code>//window
  DWORD exFlags = 0;
  if(m_bTransparent)
      exFlags |= WS_EX_LAYERED;
  Create(WS_POPUP, exFlags);
  
  std::wstring sPic(L"power-disconnected.png");
  m_pAlertPic = m_pPowerMon-&gt;GetGPPicMan()-&gt;LoadPicture(sPic.c_str());
  
  // make the window layered when using transparency
  if(m_bTransparent &amp;&amp; m_pAlertPic != nullptr)
  {
      HDC hdcScreen = GetDC(GetHandle());
      HDC hdc = CreateCompatibleDC(hdcScreen);
      HBITMAP hbmpold = (HBITMAP)SelectObject(hdc, m_pAlertPic-&gt;GetBuffer());
  
      POINT dcOffset = {0, 0};
      SIZE size = {ww, wh};
  
      BLENDFUNCTION bf = {AC_SRC_OVER, 0, (int) (2.55 * 100), AC_SRC_ALPHA}; // blend function combines opacity and pixel based transparency
      UpdateLayeredWindow(GetHandle(), hdcScreen, NULL, &amp;size, hdc, &amp;dcOffset, RGB(255, 255, 255), &amp;bf, ULW_ALPHA);
      SelectObject(hdc, hbmpold);
      DeleteDC(hdc);
      ReleaseDC(GetHandle(), hdcScreen);
  }
  </code></pre>
  
  <p>and the message loop</p>
  
  <pre><code>int WindowAlert::WndProc(Gnaq::WindowBase* pWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  {
     switch(msg)
     {
     case WM_CLOSE:
         Hide();
         return 1;
     case WM_PAINT:
         // only draw when the widow is not transparent
         // layered window redraw them self
         if(!m_bTransparent)
             m_pCanvas-&gt;Draw(m_pGraphics);
         break;
     case WM_LBUTTONUP:
         pWnd-&gt;Hide();
         m_bDismised = true;
         break;
     }
     return DefWindowProcW(pWnd-&gt;GetHandle(), msg, wParam, lParam);
  </code></pre>
  
  <p>}</p>
  
  <p>So this is the result I get
  <img src="https://i.stack.imgur.com/uSiV5.png" alt="UpdateLayeredWindow result">
  As you can see with this method I'm getting white borders where is should actually be fully transparent, but the semi transparent parts do work correctly.</p>
  
  <p>here's what I've tried that gave me a "useful" change.
  First I just tried to add the ULW_COLORKEY flag to hide the white color</p>
  
  <pre><code>UpdateLayeredWindow(GetHandle(), hdcScreen, NULL, &amp;size, hdc, &amp;dcOffset, RGB(255, 255, 255), &amp;bf, ULW_ALPHA | ULW_COLORKEY);
  </code></pre>
  
  <p>And the result.
  <img src="https://i.stack.imgur.com/WqI4l.png" alt="ULW_COLORKEY"></p>
  
  <p>So this hides the white border but also all the white in the picture.
  Next thing I've tried was using SetLayeredWindowAttributes in combination of UpdateLayeredWindow, without the ULW_COLORKEY flag</p>
  
  <pre><code>SetLayeredWindowAttributes(GetHandle(), 0xFFFFFF00, 255, LWA_COLORKEY);
  </code></pre>
  
  <p>Also in the window proc enable the paint, like this</p>
  
  <pre><code>case WM_PAINT:
      m_pCanvas-&gt;Draw(m_pGraphics);
      break;
  </code></pre>
  
  <p>This way I'm visually getting what I want like this
  <img src="https://i.stack.imgur.com/PesJC.png" alt="SetLayeredWindowAttributes"></p>
  
  <p>But the problem with his approach is that it the complete window is click able while with just using the UpdateLayeredWindow only the parts that should be fully transparent are click able like it should be. I also have the feeling with this last approach that it is more a "hack" than a decent approach.</p>
  
  <p>So i hope that someone can tell me what I'm doing wrong.</p>