1

I created a setup with custom wizard pages and custom background images. The problem is with non-standard DPI systems.

When I run this setup the background images are not properly showing. How can I detect the DPI size and use custom settings for wizard pages?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user830054
  • 299
  • 2
  • 5
  • 14

3 Answers3

4

Deanna mentioned that the DPI can be detected like so:

You can detect the DPI size using the TGraphicsObject.PixelsPerInch property and load a different image.

However, the InnoSetup documentation suggests that TGraphicsObject has no PixelsPerInch attribute, it is instead an attribute of TFont objects.

The DPI can therefore be detected and custom settings be implemented using code similar to this:

procedure CheckDPI;
var
  CurrentDPI, StandardDPI, MediumDPI, LargeDPI: Integer;
begin
  { Get the current 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
  else if (CurrentDPI >= MediumDPI) and (CurrentDPI < LargeDPI) then
  begin
    { Execute some custom code for medium to large DPI }
  end
  else if (CurrentDPI >= LargeDPI) then
  begin
    { Execute some custom code for large DPI or above }
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Tom Clarke
  • 118
  • 8
  • Since Windows 8.1 users can adjust DPI scaling per monitor and `Font.PixelsPerInch` returns DPI value always for the primary monitor, so you are a bit *outdated* with this approach ;-) Except that you should listen to the `WM_DPICHANGED` notifications and adapt the window to the changed DPI (where this change can be just moving the window to a monitor with different DPI settings). To get the DPI for a certain window one might [`try this`](http://pastebin.com/ZMWV7eDQ) (it's totally untested by me, written from Windows SDK). – TLama Dec 09 '14 at 21:07
  • See [Inno Setup WizardImageFile looks bad with font scaling on Windows 7](http://stackoverflow.com/q/26543603/850848) for example how this is applied in practice to `WizardImageFile` and `WizardSmallImageFile`. – Martin Prikryl Jun 23 '15 at 12:49
  • @TLama While that's true, Inno Setup does not announce per-monitor DPI awareness in its manifest. So for Inno Setup the system will virtualize all screens to the same DPI. – Martin Prikryl Apr 29 '17 at 17:55
4

The "most correct" way is to have alternative images for small and larger fonts mode. The "slightly less correct" method is to pad the background so it shows that instead of shrinking. The "very wrong" method is to try and adjust the form layout/size to suit.

You can detect the DPI size using the TGraphicsObject.PixelsPerInch property and load a different image.

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • Thanks for the answer, but I can't find any code to that. Why inno just cant dettect automatically and scale from 96 to any dpi? – user830054 Jul 07 '11 at 12:54
  • It does do it automatically. The image itself however is a fixed pixel size and so is physically smaller on a higher DPI screen/setting. I've already given you the property to check, you just need to extract a different image to suit (As you're already extracting the image to use anyway) – Deanna Jul 07 '11 at 13:08
-3

Define the following functions by yourself to cheat Inno Setup:

function ScaleX(Value: Integer): Integer;
begin
  Result := Value;
end;

function ScaleY(Value: Integer): Integer;
begin
  Result := Value;
end;

Bing GO~

TLama
  • 75,147
  • 17
  • 214
  • 392
liujw
  • 7
  • 1
    How would it cheat Inno Setup ? Well, these functions might be called, but from your own script, and so it makes a little sense to me why to even call them in the first place. – TLama May 15 '14 at 07:04
  • 1
    The answer is non sensical and won't have an effect on anything, let alone the issue in the question. Not only will the function not be called, they are a non operation. – Deanna Dec 09 '14 at 09:23