感謝Sertac Akyuz我找到了解決我的問題。在包含縮放代碼的單元的初始化部分中,我可以在DPI感知和非DPI感知之間切換。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
這是實際的代碼轉換:不要在應用程序清單,可以通過這樣提供一個定製清單來實現此設置(使用控制裝修,並與當前用戶的權限運行)是非常重要的根據註冊表項:
// Set DPI Awareness depending on a registry setting
with TRegIniFile.create('SOFTWARE\' + SRegName) do
begin
setting := readInteger('SETTINGS', 'scale', 0);
Free;
end;
handle := LoadLibrary('shcore.dll');
if handle <> 0 then
begin
setProcessDPIAwareness := GetProcAddress(handle, 'SetProcessDpiAwareness');
if Assigned(setProcessDPIAwareness) then
begin
if setting < 2 then
// setting <2 means no scaling vs Windows
setProcessDPIAwareness(0)
else
// setting 2: 120%, 3: 140% vs. Windows
// The actual used scaling factor multiplies by windows DPI/96
setProcessDPIAwareness(1);
end;
FreeLibrary(handle);
// Get windows scaling as Screen.PixelsPerInch was read before swiching DPI awareness
// Our scaling routines now work with WinDPI instead of Screen.PixelsPerInch
WinDPI:= Screen.MonitorFromWindow(application.handle).PixelsPerInch;
end;
這個片段的最後一行檢索當前監視器的當前DPI爲screen.pixelsperinch好像之前被初始化,並始終返回96作爲非DPI感知的應用程序。我在隨後的所有縮放計算中使用winDPI的值,並且它非常完美。
您提到的設置是「」嗎?如果是這樣,請參見[SetProcessDpiAwareness](https://msdn.microsoft.com/en-us/library/dn302122(v = vs.85).aspx)中的註釋。 –
謝謝,我會盡力的! – MichaSchumann
爲什麼我的問題被拒絕? – MichaSchumann