Einzelnen Beitrag anzeigen

rabatscher

Registriert seit: 13. Dez 2007
Ort: Bruck an der Mur
61 Beiträge
 
#10

AW: Low/High DPI zur Laufzeit ändern?

  Alt 16. Nov 2018, 11:48
Wir benutzen folgende Unit um das Per Registry zu erledigen:
Die Unit muss unbedingt als erstes (bzw. gleich nach der memory manager unit) eingefügt werden.

Delphi-Quellcode:
unit HighDPIInit;

// note this unit needs to be added to the project BEFORE any unit that uses controls.pas!!!!
// -> otherwise the screen variable is wrongly initialized

interface

const
  Process_DPI_Unaware = 0;
  Process_System_DPI_Aware = 1;
  Process_Per_Monitor_DPI_Aware = 2;

type
  TSetProcessDPIAwareness = function (value : LongWord) : HRESULT; stdcall;

var setProcessDPIAwareness : TSetProcessDPIAwareness;
    hdl : THandle;

implementation

uses Windows, registry, DarwinConsts;


initialization
  with TRegIniFile.Create('', KEY_READ or KEY_WOW64_64KEY) do
  try
     RootKey := HKEY_LOCAL_MACHINE;
     OpenKey('your section here', False);
     if not ReadBool('','HighDPIAware', False) then
        exit;
  finally
       Free;
  end;

  // ###############################################
  // #### Enable high dpi awareness
  // ###############################################

  hdl := LoadLibrary('Shcore.dll');
  if hdl <> 0 then
  begin
       setProcessDPIAwareness := GetProcAddress(hdl, 'SetProcessDpiAwareness');
       if Assigned(setProcessDPIAwareness) then
          setProcessDPIAwareness(Process_System_DPI_Aware);

       FreeLibrary(hdl);
  end;
end.
  Mit Zitat antworten Zitat