procedureCheckDPI; var CurrentDPI, StandardDPI, MediumDPI, LargeDPI: Integer; begin { Get the current DPI, 从向导页面的字体中得到当前的DPI } CurrentDPI := WizardForm.Font.PixelsPerInch; { Store defaults determined from Windows DPI settings } StandardDPI := 96; { 100% } MediumDPI := 120; { 125% } LargeDPI := 144; { 150% }
if (CurrentDPI >= StandardDPI) and (CurrentDPI < MediumDPI) then begin { Execute some custom code for small to medium DPI } end elseif (CurrentDPI >= MediumDPI) and (CurrentDPI < LargeDPI) then begin { Execute some custom code for medium to large DPI } end elseif (CurrentDPI >= LargeDPI) then begin { Execute some custom code for large DPI or above } end; end;
[Setup] ; Use 100% images by default WizardImageFile=WizardImage 100.bmp WizardSmallImageFile=WizardSmallImage 100.bmp
[Files] ; Embed all other sizes to the installer Source: "WizardImage *.bmp"; Excludes: "* 100.bmp"; Flags: dontcopy Source: "WizardSmallImage *.bmp"; Excludes: "* 100.bmp"; Flags: dontcopy
[Code] functionGetScalingFactor: Integer; begin if WizardForm.Font.PixelsPerInch >= 192then Result := 200 else if WizardForm.Font.PixelsPerInch >= 144then Result := 150 else if WizardForm.Font.PixelsPerInch >= 120then Result := 125 else Result := 100; end;
procedureLoadEmbededScaledBitmap(Image: TBitmapImage; NameBase: string); var Name: String; FileName: String; begin Name := Format('%s %d.bmp', [NameBase, GetScalingFactor]); ExtractTemporaryFile(Name); FileName := ExpandConstant('{tmp}\' + Name); Image.Bitmap.LoadFromFile(FileName); DeleteFile(FileName); end;
procedureInitializeWizard; begin { If using larger scaling, load the correct size of images } if GetScalingFactor > 100then begin LoadEmbededScaledBitmap(WizardForm.WizardBitmapImage, 'WizardImage'); LoadEmbededScaledBitmap(WizardForm.WizardBitmapImage2, 'WizardImage'); LoadEmbededScaledBitmap(WizardForm.WizardSmallBitmapImage, 'WizardSmallImage'); end; end;
functionIsWindows81OrLater: Boolean; begin Result := GetWindowsVersion >= $06030000; end;
functionGetPrimaryMonitorDPI: Integer; var DC: HDC; begin // no need for try..finally block here; just get the desktop DC handle, // get the DPI and release the obtained handle DC := GetDC(0); Result := GetDeviceCaps(DC, LOGPIXELSY); ReleaseDC(0, DC); end;
functionGetWindowMonitorDPI(Handle: HWND): Integer; var HorzDPI: UINT; VertDPI: UINT; Monitor: HMONITOR; begin // if we're not on at least Windows 8.1, then return the primary monitor // DPI since earlier systems did not allow per monitor DPI settings ifnot IsWindows81OrLater then Result := GetPrimaryMonitorDPI else // otherwise determine which monitor the given window intersects and try // to get DPI settings of the found monitor (if any; check MSDN docs for // the explanation and other options how to find the nearest monitor) begin // try to get the monitor which the window intersects Monitor := MonitorFromWindow(Handle, MONITOR_DEFAULTTONULL); // if there's any, then... if Monitor <> 0then begin // try to get DPI for that monitor; if it succeeds, return the value, // raise an exception otherwise (for details check the MSDN docs) if GetDpiForMonitor(Monitor, MDT_DEFAULT, HorzDPI, VertDPI) = S_OK then Result := VertDPI else RaiseException('GetDpiForMonitor function call failed!'); end else RaiseException('The given window does not intersect any monitor!'); end; end;