"crop" Windows 8/10 上没有储物柜表格的屏幕储物柜表格后面的区域如何出现在最终结果中?

How "crop" a area behind of a screen locker Form on Windows 8/10 without locker Form appear on final result?

我有一个远程管理工具,我很难在 Windows 8/10 上 "crop" 屏幕储物柜表格后面的确定区域没有储物柜表格出现在最终结果中(在我的情况下是一个图像文件 (.bmp),稍后将显示给客户。

在 Windows Vista/7 上工作正常。那我想知道为什么在 Windows 8/10 而不是 "cropped" 区域是网站(在屏幕储物柜表格后面),这个区域是储物柜表格?

例如(注意所有灰色区域都是锁屏窗体):

这里是屏幕储物柜表单的设置,代码如下分别在客户端生成一个 "cropped" 区域:

object Form2: TForm2
  Left = 648
  Top = 176
  AlphaBlend = True
  BorderStyle = bsNone
  Caption = 'Form2'
  ClientHeight = 507
  ClientWidth = 687
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  Position = poDesigned
  OnClose = FormClose
  OnCreate = FormCreate
  OnShow = FormShow
  DesignSize = (
    687
    507)
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 0
    Top = 0
    Width = 105
    Height = 105
    AutoSize = True
  end

procedure TForm1.CS1Read(Sender: TObject; Socket: TCustomWinSocket);
var
  StrCommand: string;
  X1, X2, Y1, Y2: Integer;
  Bmp: TBitmap;
  DeskTopDC: HDc;
  DeskTopCanvas: TCanvas;
  R: TRect;
  List : TStringList;

begin
  StrCommand := Socket.ReceiveText;

   if Pos('¬', StrCommand) > 0 then // Receiving dimensions of area (in this case of some website) for save to file.
  begin

    List := TStringList.Create;
    Bmp := TBitmap.Create;

    try

      ExtractStrings(['¬'], [], PChar(StrCommand), List);

      X1 := StrToIntDef(List[0], 0) - Form2.Left - 2; // Form2 is the Form that copper whole desktop (locker screen)
      Y1 := StrToIntDef(List[1], 0) - Form2.Top - 2;
      X2 := StrToIntDef(List[2], 0) - Form2.Left - 2;
      Y2 := StrToIntDef(List[3], 0) - Form2.Top - 2;

      R := Rect(X1, Y1, X2, Y2);

      Bmp.SetSize(R.Width, R.Height);

         DeskTopDC := GetWindowDC(GetDesktopWindow); // Windows Vista/7

      if ( Pos('Windows 8', GetSOComputer) > 0 ) or
         ( Pos('Windows 10', GetSOComputer) > 0 ) then

      if BrowserHandle > 0 then
         DeskTopDC := GetWindowDC(BrowserHandle); // If is Win8/10, then device context will be window of navigator (ex: Google Chrome)
                                                  // this was necessary to that dimensions of area here be equals like was received, already
                                                  // that on server side, i see only browser window ( a way of exclude locker screen (Form2)
                                                  // of screenshot)

      DeskTopCanvas := TCanvas.Create;
      DeskTopCanvas.handle := DeskTopDC;

      Bmp.Canvas.CopyRect(Rect(0, 0, Bmp.Width, Bmp.Height), DeskTopCanvas, R);

      Bmp.SaveToFile(GetSpecialFolder(CSIDL_LOCAL_APPDATA, True) + 'area.bmp'); // Saving area created to AppData\Local for show to client later 

      ReleaseDC(GetDeskTopWindow, DeskTopDC);

    finally
      List.Free;
      Bmp.Free;
    end;
  end;

end;

我发现这是 Aero 组合产生的一个问题,不可能在 Windows8/8.1/10 上禁用,已经在 Windows Vista/7 上是可能的(和上面的代码总是工作正常)。

然后我找到的解决方案是在 Form2(储物柜表格)上创建一个 "hole" 使用:

  1. CreateRectRgn
  2. CombineRgn
  3. SetWindowRgn

  1. 使用收到的尺寸创建区域。

  2. 保存到文件。

  3. 关闭储物柜表格孔。

所以,GetWindowDC 没有得到锁屏表格。