Delphi 7 - 不捕获表单的屏幕截图 - Windows 8 - DWM.exe

2023-11-30

朋友们,

需要对没有我的表格的所有桌面进行屏幕截图并加载到 TImage 中。 在 Windows XP、7 中成功 - 只需 ALPHABLEND = TRUE + SCREENSHOT PROCEDURE。

但相同的代码在 Windows 8 中不起作用 - 捕获所有屏幕,包括表单。

我知道问题与 AERO - DWM.EXE - 成功使用 pssuspend.exe (sysinternals) - 挂起 winlogon.exe 并杀死 dwm.exe 有关

有人可以告诉我如何在 Windows 8 中捕获所有桌面而不需要我的表单吗?

prntscr.com/314rix - WIN7 中的成功

prntscr.com/314tj7 - 在 WIN8 中失败

prntscr com/31502u - 在 WIN8 中暂停 WINLOGON.EXE 并杀死 DWM.EXE

www sendspace com/file/b5oxhb - 源代码

// FORM -> ALPHABLEND -> TRUE


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,
  Clipbrd;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    ScrollBox1: TScrollBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ScreenShot(DestBitmap: TBitmap);
var
  DC: HDC;
begin
  DC:=GetDC(GetDesktopWindow);
  try
    DestBitmap.Width:=GetDeviceCaps(DC, HORZRES);
    DestBitmap.Height:=GetDeviceCaps(DC, VERTRES);
    BitBlt(DestBitmap.Canvas.Handle,0,0,DestBitmap.Width,DestBitmap.Height,DC,0,0,SRCCOPY);
  finally
    ReleaseDC(GetDesktopWindow, DC);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ScreenShot(Image1.Picture.Bitmap);
end;

end.

如果您想在不显示窗口的情况下截取屏幕截图:在截取屏幕截图之前隐藏窗口:

procedure TForm1.Button1Click(Sender: TObject);
var
    desktop: TGraphic;
    fDisable: BOOL;
begin
    {
        Capture a screenshot without this window showing
    }
    //Disable DWM transactions so the window hides immediately
    if DwmApi.DwmCompositionEnabled then
    begin
        fDisable := True;
        OleCheck(DwmSetWindowAttribute(Self.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, @fDisable, sizeof(fDisable)));
    end;
    try
        //Hide the window
        Self.Hide;
        try
            //Capture the desktop
            desktop := CaptureDesktop;
        finally
            //Re-show our window
            Self.Show;
        end;
    finally
        //Restore animation transitions
        if DwmApi.DwmCompositionEnabled then
        begin
            fDisable := False;
            DwmSetWindowAttribute(Self.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, @fDisable, sizeof(fDisable));
        end;
    end;

    //Save the screenshot somewhere
    desktop.SaveToFile('d:\temp\ss.bmp');
end;

神奇的事情发生在:

function CaptureDesktop: TGraphic;
const
    CAPTUREBLT = $40000000;
    SM_XVIRTUALSCREEN        = 76;
    SM_YVIRTUALSCREEN        = 77;
    SM_CXVIRTUALSCREEN       = 78;
    SM_CYVIRTUALSCREEN       = 79;
var
    nDesktopWidth, nDesktopHeight: Integer;
    tmpBmp: TBitmap;
    hwndDesktop: HWND;
    dcDesktop: HDC;
begin
    Result := nil;

    {
        GetWindowRect(GetDesktopWindow)
        is completely wrong. It will intentionally return only the rectangle of the primary monotor. See MSDN.
    }

    { Cannot handle dpi virtualization
    //Get the rect of the entire desktop; not just the primary monitor
    ZeroMemory(@desktopRect, SizeOf(desktopRect));
    for i := 0 to Screen.MonitorCount-1 do
    begin
        desktopRect.Top := Min(desktopRect.Top, Screen.Monitors[i].Top);
        desktopRect.Bottom := Max(desktopRect.Bottom, Screen.Monitors[i].Top + Screen.Monitors[i].Height);
        desktopRect.Left := Min(desktopRect.Left, Screen.Monitors[i].Left);
        desktopRect.Right := Max(desktopRect.Right, Screen.Monitors[i].Left + Screen.Monitors[i].Width);
    end;

    //Get the size of the entire desktop
    nDesktopWidth := (desktopRect.Right - desktopRect.Left);
    nDesktopHeight := (desktopRect.Bottom - desktopRect.Top);
    }

    //Also doesn't handle dpi virtualization; but is shorter and unioning rects
    nDesktopWidth := GetSystemMetrics(SM_CXVIRTUALSCREEN);
    nDesktopHeight := GetSystemMetrics(SM_CYVIRTUALSCREEN);

    tmpBmp:= TBitmap.Create;
    try
        tmpBmp.Width := nDesktopWidth;
        tmpBmp.Height := nDesktopHeight;

        //dcDesktop := GetDC(0); //
        hwndDesktop := GetDesktopWindow;
        dcDesktop := GetDC(hwndDesktop); //GetWindowDC(0) returns the DC of the primary monitor (not what we want)
        if dcDesktop = 0 then
            Exit;
        try
            if not BitBlt(tmpBmp.Canvas.Handle, 0, 0, nDesktopWidth, nDesktopHeight, dcDesktop, 0, 0, SRCCOPY or CAPTUREBLT) then
                Exit;
        finally
            ReleaseDC(0, dcDesktop);
        end;
    except
        tmpBmp.Free;
        raise;
    end;
//  CaptureScreenShot(GetDesktopWindow, Image, false);

    Result := tmpBmp;
end;

应用程序运行时的屏幕:

enter image description here

以及保存的屏幕截图:

enter image description here

Note:发布到公共领域的任何代码。无需归属。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Delphi 7 - 不捕获表单的屏幕截图 - Windows 8 - DWM.exe 的相关文章

  • logback的“谨慎模式”是如何实现的?

    The 审慎模式 http logback qos ch manual appenders html prudentlogback 中的序列化所有 JVM 之间的 IO 操作 写入同一文件 可能运行在不同的主机上 在其他日志记录框架中 如果
  • 如何在Delphi中将对象方法作为参数传递,然后调用它?

    我担心这可能是一个有点愚蠢的问题 但这让我很难过 我正在寻找将对象的方法传递到过程中的最简单的方法 以便过程可以调用对象的方法 例如 超时后 或者可能在不同的线程中 所以基本上我想 捕获对对象方法的引用 将该引用传递给过程 使用该引用 从过
  • 为什么 Delphi 中的 ADO Next 记录处理速度变慢?

    我有一个多年前开发的 Delphi 4 程序 它使用Opus 直接访问 http sourceforge net projects directaccess 按顺序搜索 Microsoft Access 数据库并检索所需的记录 Delphi
  • 使用 TestNG 运行并行测试时捕获 WebDriver 屏幕截图

    我目前正在通过分别重写 TestListenerAdapter 方法 onTestFailure 和 onTestSuccess 来捕获 TestNG 中失败和成功的屏幕截图 为此 您需要指定要截取屏幕截图的驱动程序 我的问题 在方法级别并
  • 使用 PutBlock 并将字节数组全部设置为零的 EIPHTTPProtocolExceptionPeer 异常

    使用 Delphi XE2 Update 3 我在将零字节块上传到 Azure 时遇到问题 当我说零字节时 我指的是每个元素设置为零的字节数组 不是零长度 例如 var ConInfo TAzureConnectionInfo RespIn
  • 如何在表单上绘制半透明图像?

    我想在 Delphi 窗体上绘制半透明图像 但由于某种原因它不起作用 Here is the original PNG border is semi transparent 我将图像加载到TImage object Image1 Trans
  • Windows Aero - 以编程方式禁用视觉效果

    有谁知道是否有一个 API 可以通过编程方式禁用 启用特定的 Windows 视觉效果 例如 启用透明玻璃 或 启用 Aero Peek 我指的效果是在以下位置配置的效果 系统 高级系统首选项 高级 选项卡 性能设置 自定义 我正在为 Wi
  • 如何在按键时识别 unicode 键?

    我的应用程序使用 unicode 字符 并且我有几个文本字段 我想限制用户输入特殊字符 例如 begin if not Key in a z A Z 0 9 13 8 then Key 0 if Key 13 then bOk Click
  • 使用 Delphi 读取 Excel 电子表格

    我需要使用 Delphi 2010 读取和写入 Excel 电子表格 没什么花哨的 只需读取和写入不同工作表上特定单元格和范围的值 需要在没有安装 Excel 的情况下工作并支持 Excel 2007 我看过的一些东西 我尝试过使用ADO
  • 似乎有时 Delphi 是区分大小写的 - “覆盖方法应该与祖先的大小写匹配”

    今天我遇到了一个 奇怪 的提示 覆盖方法 xxxx 应匹配祖先 yyyy 的大小写 解决方案是完全按照祖先中的方式声明方法名称 我相信这是自 Delphi Net 编译器以来编译器中保留的东西 与祖先中完全相同的方法声明方法使编译器 沉默
  • 为什么 TImage 旋转我的图像?

    编写一个移动应用程序 它从安全网站提取图像 如下所示 第一个图像 提取不正确 注意网络版本与移动版本 第二个图像在网站上正确显示 但 Delphi TImage 由于某种原因正在旋转它我不明白为什么 旋转设置为 0 并且在 TImage 组
  • (发件人:TObject)

    发件人 TObject 是什么意思 如 procedure TForm1 Button1Click Sender TObject var s Integer begin end Sender 是对触发事件的组件的引用 在这种情况下 Send
  • Delphi + Synapse:如何检查我是否仍然连接

    我在用TTCPBlockSocket http synapse ararat cz doc help blcksock TTCPBlockSocket html对于 TCP IP 应用程序 问题是我无法确定连接何时丢失 GetLastErr
  • 如何在 Android 上以编程方式截取屏幕截图?

    如何不通过任何程序而是通过代码截取手机屏幕的选定区域的屏幕截图 以下代码允许将我的屏幕截图存储在 SD 卡上 并在以后满足您的任何需求 首先 您需要添加适当的权限来保存文件
  • Windows 更新后 Active 设置为 False 时 TIdHttpServer 冻结

    我们有一个 Indy 版本 10 6 1 5235 TIdHttpServer 服务 多年来一直与 Delphi 2007 配合良好 在最新的 Windows 更新 KB4338815 和 KB4338830 之后 我们注意到当 TIdHt
  • 新编译的应用程序需要 UAC/elevation?

    我有一个系统 我将其设置为普通的 UAC 并在我的 delphi 环境中编译名为 ka exe 的项目 并为其创建一个 installshield 项目 设置完毕 一切顺利 但每当我开始我的程序时 它都需要提升 而我不知道为什么 为了确保
  • 如何捕获 UITableView / UIScrollView 完整内容的 UIImage 并使其在 ios 设备上工作

    我正在使用这段非常优雅的代码获取 UIScrollView 的屏幕截图 包括屏幕外部分 https stackoverflow com questions 3539717 getting a screenshot of a uiscroll
  • Soap Delphi 客户端因 1MB 调用超时而结束

    我们正在开发 SOAP Web 服务 Apache PHP 所有小规模调用都运行良好 但对于 1Mb 的 Soap 调用 HTTPS 调用大小为 1MB 我们的 Delphi Soap 客户端在除一台 PC 之外的所有 PC 上都因超时而停
  • 让线程在窗体关闭时保持运行

    我在我的应用程序上创建了一个同步线程 我想知道如果我关闭申请表 是否有办法让该线程保持打开状态 直到完成同步过程 调用线程的WaitFor方法在您的 DPR 文件中 之后Application Run线 如果线程已经运行完毕 那么WaitF
  • 指针^ 与 s[1]

    在读取数据的函数中 数据含义只字符串 从磁盘 我应该更喜欢哪个 哪个更好 A DiskStream Read Pointer s Count or B DiskStream Read s 1 Count Note 我知道两者都有相同的结果

随机推荐