GetDpiForMonitor Delphi 7 用于 per-monitor DPI 感知

GetDpiForMonitor with Delphi 7 for per-monitor DPI awareness

WinAPI 函数 GetDpiForMonitor 没有 header 对 Delphi 7 的翻译,在互联网上搜索我也找不到。

如果有人有显示如何使用 Delphi 7 中的此 WinAPI 函数的示例代码,那将大有帮助。

下面是Delphi7中动态加载DLL和调用函数的方法:

Type
  TMONITOR_DPI_TYPE = (
    MDT_EFFECTIVE_DPI {= 0},
    MDT_ANGULAR_DPI   {= 1},
    MDT_RAW_DPI       {= 2},
    MDT_DEFAULT       {= MDT_EFFECTIVE_DPI });

var
  dpiX              : UINT;
  dpiY              : UINT;
  ErrCode           : HResult;
  hShcore           : THandle;
  GetDpiForMonitor  : function(monitor: HMONITOR; dpiType: TMONITOR_DPI_TYPE; var dpi, dpiY: UINT): HRESULT; stdcall;

begin
  hShcore := GetModuleHandle('Shcore');
  If hShcore <> 0 then GetDpiForMonitor := GetProcAddress(hShcore,'GetDpiForMonitor');
  If @GetDpiForMonitor <> nil then 
    ErrCode := GetDpiForMonitor(Monitor.Handle,MDT_EFFECTIVE_DPI,dpiX,dpiY);
end;