How can I make another application window transparent?

I know how to make my application transparent using layered Windows, but I want to make another application transparent (like notepad). I wrote such code, but it does not work with windows other than the main application window:

SetWindowLongPtr(WindowFromPoint(p), GWL_EXSTYLE, 
                 GetWindowLongPtr(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(WindowFromPoint(p), 0, (255 * 50) / 100, LWA_ALPHA);

where p is the point on the screen (for example, the window that I select with the mouse)

I am also wondering if there is a way to do this directly from Windows 7 (not necessarily software). I believe that there should be a way to do this, since each application is displayed on its own surface, and DWM combines them into the final image.

+3
source share
1 answer

SetWindowLongPtr, , GetWindowLongPtr, ?

Windows Server 2003 Windows 7

   POINT ptScreen = pt;
   ClientToScreen(pwnd->hdr.hwnd, &ptScreen);
   HWND hctl = WindowFromPoint(ptScreen);
   if (IsWindow(hctl))
      {
      LONG lExStyle = GetWindowLong(hctl, GWL_EXSTYLE);
      lExStyle ^= WS_EX_LAYERED;
      SetWindowLong(hctl, GWL_EXSTYLE, lExStyle);
      SetLayeredWindowAttributes(hctl, 0, 
          (lExStyle & WS_EX_LAYERED) ? (255 * 50) / 100 : 255, 
          LWA_ALPHA);
      }
   }

, WindowFromPoint , , . , , , , - . ( )

+2

Source: https://habr.com/ru/post/1733624/


All Articles