Windows10中的Delphi桌面屏幕截图,GetDeviceCaps问题 [英] Delphi desktop screenshot in Windows10, issue with GetDeviceCaps

查看:101
本文介绍了Windows10中的Delphi桌面屏幕截图,GetDeviceCaps问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取正确的屏幕尺寸以在Windows10中进行屏幕截图?似乎得到了不正确的值(也许是DPI问题?)

How can I get the correct screen size to take a screenshot in Windows10? it seems to get incorrect values (maybe DPI issue?)

ie

// screenshot
b := TBitmap.Create;
DC := GetDC(GetDesktopWindow);
try
  b.Width  := GetDeviceCaps (DC, HORZRES) ;
  b.Height := GetDeviceCaps (DC, VERTRES) ;
  BitBlt(b.Canvas.Handle, 0, 0, b.Width, b.Height, DC, 0, 0, SRCCOPY) ;
finally
  ReleaseDC (GetDesktopWindow, DC) ;
end;

在4K屏幕上只会捕获左上角的一小部分。

on a 4K screen will only capture a small portion on the upper left corner.

推荐答案

您需要使您的应用程序完全具备DPI意识,以便获取用于拍摄屏幕快照的适当值。

You need to make your application fully High DPI aware in order to get proper values for taking screen snapshot.

您可以通过在应用清单中添加以下部分来做到这一点

You can do that by adding following section into your application manifest

  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true/PM</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>






Windows 10自定义清单的完整示例


Complete example of custom manifest for Windows 10

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
      <application> 
            <!-- Windows 10 --> 
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>

            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

            <!-- Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>

            <!-- Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>

            <!-- Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
      </application> 
  </compatibility>

  <assemblyIdentity
    type="win32"
    name="MyApplication"
    version="1.0.0.0" 
    processorArchitecture="*"/>

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>

  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true/PM</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>

</assembly>






注意:Windows 10引入了逐监视器DPI意识。上面的清单以 true / PM 的值( PM -每个监视器)打开了意识。


Note: Windows 10 have introduced Per-monitor DPI awareness. Above manifest turns that awareness on with true/PM value (PM - Per Monitor).

自从Delphi在西雅图引入对Per-Monitor DPI的支持以来,使用较早版本编译的应用程序将无法在具有不同DPI设置的多显示器设置中正确缩放。 Windows10。根据应用程序和用户群的目的,您可以忍受这种行为,或者必须升级到最新的Delphi(同样重要的是要注意,这是一项新功能,并且确实存在一些错误,这些错误可能或与您的情况无关)

Since Delphi introduced support for Per-Monitor DPI in Seattle, applications compiled with older versions will not properly scale in multi-monitor setups that have different DPI settings for each monitor on Windows 10. Depending on the purpose of your application and user base you can either live with such behavior or you would have to upgrade to newest Delphi (it is also important to note that this is new feature and it does have some bugs that may or not be relevant in your case)

这篇关于Windows10中的Delphi桌面屏幕截图,GetDeviceCaps问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆