-1

For Capture the Screen Shot of the Active Window, I use a source code Capture the Screen Shot of the Active Window with this code in Delphi:

 procedure ScreenShot(activeWindow: bool; destBitmap : TBitmap) ;
 var
    w,h : integer;
    DC : HDC;
    hWin : Cardinal;
    r : TRect;
 begin
    if activeWindow then
    begin
      hWin := GetForegroundWindow;
      dc := GetWindowDC(hWin) ;
      GetWindowRect(hWin,r) ;
      w := r.Right - r.Left;
      h := r.Bottom - r.Top;
    end
    else
    begin
      hWin := GetDesktopWindow;
      dc := GetDC(hWin) ;
      w := GetDeviceCaps (DC, HORZRES) ;
      h := GetDeviceCaps (DC, VERTRES) ;
    end;

    try
     destBitmap.Width := w;
     destBitmap.Height := h;
     BitBlt(destBitmap.Canvas.Handle,
            0,
            0,
            destBitmap.Width,
            destBitmap.Height,
            DC,
            0,
            0,
            SRCCOPY) ;
    finally
     ReleaseDC(hWin, DC) ;
    end;
 end; 

Usage:

 var
    b:TBitmap;
 begin
   b := TBitmap.Create;
   try
     ScreenShot(TRUE, b) ;
     Image1.Picture.Bitmap.Assign(b) ;
   finally
     b.FreeImage;
     FreeAndNil(b) ;
   end;

How can I convert that to take a screenshot of a Protected active software like Oxynger KeyShield?

user3195815
  • 11
  • 1
  • 1

1 Answers1

1

The Windows Display Manager (WDM) on Windows 7 and above supports SetWindowDisplayAffinity with the flag WDA_MONITOR, which prevents the window image from being captured with a screen shot of any sort.

There are restrictions on the API calls it blocks, and it only works on DWM-composited windows. See my answer here for an example of its use and a little more information, or see the MSDN documentation I linked above.

If this is the technique being used by KeyShield to protect the window from being captured, you'll have to find out which of the APIs that are not blocked by SetWindowDisplayAffinity with the WDA_MONITOR flag and see if you can use one of them to bypass the restriction. It's part of the OS functionality though, so I'd imagine that the list of uncovered APIs is going to be fairly short.

Community
  • 1
  • 1
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • One obvious question this answer raises is, "why not use `SetWindowDisplayAffinity` on the window that the OP want to capture to have its display affinity restriction removed?". Documenation you refer or the link you've posted does not mention why it cannot be used to revert affinity. – Sertac Akyuz Mar 30 '14 at 15:24
  • @Sertac: I'm presuming it isn't that easy, based on "This feature enables **applications to protect their own onscreen window content** from being captured or copied through a specific set of public operating system features and APIs." And, prior to that, it says "support the window content protection feature" - it doesn't seem to be much of a protection system if it could simply be removed by another application. – Ken White Mar 30 '14 at 16:31
  • @SertacAkyuz, I found out what thread injection is necessary to set/unset this stuff because this function refuses to work with window owned by another process. – Free Consulting Jun 22 '14 at 01:48