【问题标题】:How capture a window that is opened inside of a “new desktop environment”?如何捕获在“新桌面环境”中打开的窗口?
【发布时间】:2016-05-21 19:29:55
【问题描述】:

大家下午好。

我想从我的远程协助工具中看到一个在“新桌面环境”中打开的窗口,但我无法使用如下常规功能看到这个窗口:

    function RandomPassword(PLen: Integer): string;
    var
      str: string;
    begin
      Randomize;
      str    := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      Result := '';
      repeat
        Result := Result + str[Random(Length(str)) + 1];
      until (Length(Result) = PLen)
    end;

        procedure Printscreen;
        var
          DCDesk: HDC;
          bmp: TBitmap;
          hmod, hmod2 : HMODULE;
          BitBltAPI: function(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): BOOL; stdcall;
          GetWindowDCAPI: function(hWnd: HWND): HDC; stdcall;

          begin

         hmod := GetModuleHandle('Gdi32.dll');
         hmod2:= GetModuleHandle('User32.dll');

         if (hmod <> 0) and (hmod2 <> 0) then begin

          bmp := TBitmap.Create;

          bmp.Height := Screen.Height;
          bmp.Width := Screen.Width;

          GetWindowDCAPI:= GetProcAddress(hmod2, 'GetWindowDC');

          if (@GetWindowDCAPI <> nil) then begin

            DCDesk := GetWindowDCAPI(GetDesktopWindow);

          end;

          BitBltAPI:= GetProcAddress(hmod, 'BitBlt');

          if (@BitBltAPI <> nil) then begin

            BitBltAPI(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DCDesk, 0, 0, SRCCOPY);

            bmp.SaveToFile('ScreenShot_------_' + RandomPassword(8) + '.bmp');

          end;

            ReleaseDC(GetDesktopWindow, DCDesk);

            bmp.Free;

            FreeLibrary(hmod);
            FreeLibrary(hmod2);

         end;
        end;

begin
   while True do
    begin
       Printscreen;
      Sleep(5000);
    end;

end.

产生this result

以已经使用Team View软件为例,屏幕截图正常出现窗口,并产生this result

那么,是否有某种方式可以像从 Team View 软件中一样在屏幕截图中查看此窗口?

欢迎所有建议。

【问题讨论】:

  • 在你的程序生命周期中只调用一次随机化,否则你会得到一些令人讨厌的惊喜。尝试循环调用 RandomPassword。
  • "graphics" 已经使用了"windows",不使用"windows" 中声明的函数你不会获得任何收益。

标签: delphi screenshot


【解决方案1】:

您似乎正在尝试获取 secure 桌面的屏幕截图。如果是这种情况,首先您必须阅读有关this topic. 的文档,因为这不是一项简单的任务(您必须了解Sessions, Desktops and Windows Stations)。此外,您的应用程序必须是从 Local SYSTEM 帐户运行的trusted process

现在你必须这样做。

推荐讲座

【讨论】:

  • 你说得对,我去研究一下。但是,如果有人(或您自己)想在这里放一些 Fraggo de código,以帮助更好地了解这一点。
  • 您必须尝试编写代码,然后在发现问题时返回新问题。但首先要开始阅读文档。
  • 参考我上面的代码和你上面建议的所有文档的解释,我的代码可以得到Session 0的截图,对吗?
  • 当前代码无法正常工作,因为您有几个缺陷,首先您必须使用try..finallytry..except 块捕获异常并保护系统资源。此外,您必须将屏幕捕获代码移动到辅助线程,因为您必须调用 SetThreadDesktop 方法才能切换到活动桌面并捕获屏幕。
  • 根据你所说的,我在 S.O. 这里找到了this relevant question。这将对我有很大帮助,主要是在 dll 注入过程中。
猜你喜欢
  • 2022-11-30
  • 1970-01-01
  • 2014-02-09
  • 1970-01-01
  • 2011-02-03
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 2014-03-24
相关资源
最近更新 更多