3

in our app we use the TWebBrowser component of Delphi to display web content. Now we have a problem if windows has scaled monitors, for example 125% scale. In this case some HTML-controls aren't rendert correctly, because the window.devicePixelRatio property in JavaScript isn't updated but stays on 1, althougt it should be 1.25 on a 125% scaled monitor.

Is there any posibillity to fix this issue? From inside JavaScript it is not possible to changes this value, but maybe from the Delphi side?

Edit: I tried out an embedded chromium and there it works fine. But currently it is not possible to move from ie to chromium.

A sample HTML:

<!DOCTYPE html>
<html>
    <body>
        <div style="width: 100px; height: 25px; border: 1px solid black; border-radius: 4px; overflow: hidden">
            <span style="font-size:10pt; white-space: pre">Long sample text</span>
        </div>
    </body>
</html>

In Embedded IE the text ist cut of

Sumafu
  • 179
  • 1
  • 3
  • 15
  • 1
    Try to run your application at least in IE8 compatibility mode. – Victoria Aug 30 '17 at 10:14
  • Our application runs with the latest IE11, and we have to do this. – Sumafu Aug 30 '17 at 10:24
  • 1
    So you run your application in IE11 compatibility mode? – Victoria Aug 30 '17 at 10:28
  • Tell me how, then I can try – Sumafu Aug 30 '17 at 10:31
  • [This way](https://stackoverflow.com/a/25843958/8041231). If you haven't done this, your app. is running in backwards compatibility IE7 mode. Just beware that IE11 mode is no good for everyone (embedded control behaves different than Internet Explorer; better try IE10 first). – Victoria Aug 30 '17 at 10:49
  • [There](https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx) is no code for compatibility mode. I also tried out some different codes, but nothing changed – Sumafu Aug 30 '17 at 10:59
  • Why code? It's a setting by which your `TWebBrowser` starts working in mode that you set (not in default IE7 mode). Optionally [you can add this](https://stackoverflow.com/a/44183405/8041231) to your HTML (that should run the site in the latest browser mode, which in your case is IE11). – Victoria Aug 30 '17 at 11:06
  • Yes, it is a setting, and for the setting you need a numeric code like 11000 for IE 11. And changing HTML is not an option. – Sumafu Aug 30 '17 at 12:59
  • I'm aware of it (IE9 should be enough I guess, but let's run it in IE11 mode). More I'm wondering if it helped. Did it help? Does `TWebBrowser` control reflect DPI changes when running in IE11 mode? – Victoria Aug 30 '17 at 13:05
  • As i said, nothing changed – Sumafu Aug 30 '17 at 13:10
  • Is the web HTML contents in your control? Can you show a sample HTML? – kobik Aug 30 '17 at 16:26
  • The HTML is not under our control. And I think that I'm not allowed to share sample code. – Sumafu Aug 31 '17 at 08:28
  • I just rebuilt the Element with the problem and added a sample above – Sumafu Aug 31 '17 at 08:35

1 Answers1

3

Even though it is obsolete, you will find that enabling FEATURE_96DPI_PIXEL for your application will return the correct pixelratio:

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
   SOFTWARE
      Microsoft
         Internet Explorer
            Main
               FeatureControl
                  FEATURE_96DPI_PIXEL
                     yourapplication.exe = (DWORD) 00000001

The recommended way is to enable the DOCHOSTUIFLAG_DPI_AWARE flag.

whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
  • I can't test now, but doesn't `X-UA-Compatible` set to `IE=edge` should take care of any compatibility issue? e.g. https://stackoverflow.com/a/44183405/937125 – kobik Aug 30 '17 at 16:30
  • Thanks for the info:) – kobik Aug 30 '17 at 18:27
  • Using an obsolet method is not an option. And for the other flag I can't find any sample or something similar, and I did not make it work. – Sumafu Aug 31 '17 at 08:27
  • @Sumafu, just add the flag to the registry, it will work (as I tried it). IE is obsolete anyway – whosrdaddy Aug 31 '17 at 08:50
  • Ok, but where in the registry? – Sumafu Aug 31 '17 at 08:51
  • Thank you, with this it works. And as long as it works with Windows 10 and latest IE, it should also works in earlier versions :D – Sumafu Aug 31 '17 at 09:58
  • @Sumafu, small sidenote if you are certain that your users are on IE9 or higher, you can also enable FEATURE_GPU_RENDERING for better performance (depends how heavy the site is you are presenting) – whosrdaddy Sep 07 '17 at 11:26