9

Currently I am testing various aspects of VCL styles enabled applications.

I noticed, that with Windows scaling higher than the default 96 dpi/100%, the icon and the title bar text of the VCL Form are too big in size - and both are to close together -, please see attached screenshots. This is especially true with higher scalings like 200% or 250% (e.g. used on 4K displays and Windows 10), but even with a scaling of 144 dpi/150%, the problem is already visible.

This is true for all styles delivered with RAD Studio. High Dpi awareness for manifest is enabled via project settings. If I disable VCL Styles in the App, the icon and title bar text is correct in size.

Am I missing something here? Shouldn't the delivered styles work without such display errors out of the box with display scaling enabled? Or is there some setting somewhere I can adjust to fix this.

Thanks,

enter image description here enter image description here

Petter Hesselberg
  • 5,062
  • 2
  • 24
  • 42
Tom Major
  • 283
  • 1
  • 12
  • It's by no means perfect, but simply adding two space characters at the front of the title of every form is better than nothing, and involves no VCL-hacking. – frogb Dec 20 '16 at 23:05
  • This is a comment to the question, not an answer. It does not address fixing the visual bug; it's simply a kludgy workaround. – Ken White Dec 20 '16 at 23:27
  • I did also think on that, but if you have like 15 different forms in the app, and load other dlls with forms or execute a TOpenDialog etc., no, this is no solution. – Tom Major Dec 21 '16 at 10:24

3 Answers3

11

VCL Styles do not properly support high DPI scaling.

If you use VCL Styles, then you should remove high DPI awareness from your application manifest.


QP report requesting general high DPI support for VCL Styles: VCL styles don't scale properly under high DPI configurations

Related QC Report for NC area: Styled form's non-client area incorrectly scaled under High DPI

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
  • @Dalija Prasnikar, thanks for the info and your QC, but this won't help me right now, and I am not interested in Embarca. bashing either, I already had my share with their bugs over the years. I need to use DPI awareness in manifest, and I am searching for a solution that will work with the current 10.1 release. – Tom Major Dec 19 '16 at 22:35
  • - In Style Designer, there is Objects\Form\Image\Title\Caption with a lot of subitems, is there any property which will help? I tried to change some of them, like Left or MarginLeft, but it seems to make no difference. - Or, could someone hint me to the place in the VCL styles .pas sources where the caption text ist positioned? I would also consider changing the .pas source and link it to my project if this could fix the bug. Thanks – Tom Major Dec 19 '16 at 22:35
  • You can look at Vcl.Forms TFormStyleHook class, most likely PaintNC method. – Dalija Prasnikar Dec 20 '16 at 12:58
  • 1
    Main point of my answer is you have to choose either high DPI support or using VCL Styles. It is not single issue we are talking about here. It is complete lack of support for high DPI, because they were never designed to support high DPI to begin with. Parts that "do work" under high DPI, work just by accident and not by design. – Dalija Prasnikar Dec 20 '16 at 13:01
  • If you insist using VCL Styles with high DPI, I would suggest that before you do anything else take one form and put all controls you wish to use on it to see all the issues at once. – Dalija Prasnikar Dec 20 '16 at 13:02
  • 3
    Have a look at StyleControls from AlmediaDev. Perhaps the styling is better matched with HPDI. – LU RD Dec 20 '16 at 13:09
  • @LURD reading from their most recent announcement [ANN: StyleControls VCL v. 3.38 released!](https://plus.google.com/u/0/113589856286060397890/posts/i9AnrkhwgEb?sfc=true) they do support high DPI – Dalija Prasnikar Dec 20 '16 at 13:18
  • @LU RD, thanks for the link, look interesting, I was hoping for a native solution first, but will keep this in mind. – Tom Major Dec 21 '16 at 10:18
  • @Dalija Prasnikar, Actually, we already did this, VCL Styles on high DPI looks fine on our test, just standard components, only thing really ugly is the caption on scaled Windows, that why I asked that here. – Tom Major Dec 21 '16 at 10:20
  • 1
    I found the place in TFormStyleHook, PaintNC, which is responsible for the bug. Dalija Prasnikar was right about it. Did some tests and it looks promising for a solution, will present it here when it is working. Was hoping for a solution without patching the VCL source though :(, like changing some property in style designer. – Tom Major Dec 21 '16 at 10:27
3

Ok, here is my solution for the visual bugs, please see the attached screenshots. I did fixes in 3 places in Vcl.Forms.pas.

The first fix, commented with // Title bar fix 1, addresses the problem that the icon is not correctly drawn, even without scaling, on a default 96dpi Windows with a VCL styled application. I could fix this based on the findings about WM_GETICON, ICON_SMALL2, from James Johnston, https://stackoverflow.com/a/35067909 thanks, James, for that!

The other two fixes address the problem that the icon is drawn too big with display scaling enabled, and that the distance between the icon and the title bar text is too small. These are the fixes commented with // Title bar fix 2 and 3 in the code. GetDpi is just a getter for the current dpi value, which I get from my C sources within the application.

The result is in no way perfect, but it will do for now, with this the VCL styled application is at least acceptable under scaled circumstances.

Thanks to all for your input.

left original, right 'fixed'

Title bar fix 1

Title bar fix variables

Title bar fix 2

Title bar fix 3

Community
  • 1
  • 1
Tom Major
  • 283
  • 1
  • 12
  • 2
    For Pete's sake! Don't **ever** post images of code. Images of code are absolutely useless; you can't copy/paste, it's inaccessible to those with visual impairments, they're not available behind many corporate proxies, they absolutely stink for those using mobile devices, it's not part of searches.... and more. It's far easier to copy/paste/format text than it is to make screen captures, save to file, create the links and upload them. While I commend your wanting to share your solution, please do it correctly. – Ken White Dec 28 '16 at 23:09
  • @KenWhite I understand your point and I knew posting screenshots is no good solution for code. Thing is, I actually intended only to point out the specific locations in the 16k lines .pas file where I changed things, and I wanted this as some kind of difference view, so my focus in on the location and on the differences. – Tom Major Jan 04 '17 at 22:16
  • Those places in code aren't in **procedures** and don't have **line numbers** that would allow you to reference their locations? – Ken White Jan 04 '17 at 23:05
0

Here is a unit that allows VCL styles in DPI-aware applications.

VCL.Styles.DPIAware.pas

To use the unit just add it to the implementation uses statement of the main form and add the following code to the FormCreate handler.

procedure TFrmMain.FormCreate(Sender: TObject);
Var
  StyleDPIAwareness : TStyleDPIAwareness;
begin
  StyleDPIAwareness := TStyleDPIAwareness.Create(Self);
  StyleDPIAwareness.Parent := Self;

By default the component scales the styles at multiples of 100%. You can change that, by adding the line:

StyleDPIAwareness.RoundScalingFactor := False;

With this statement styles are scaled to whatever scaling factor results for Screen.PixelsPerInch. Most of the styles would work fine, but a few may show some visual defects.

PyScripter
  • 584
  • 5
  • 12
  • Window captions in system dialogs like TColorDialog are incorrect scaled: they become much too high. As a result the OK and cancel buttons are not visible. Also, using uCommonFunctions draws in lots of other units such as SynEdit related which are totally unrelated to what this unit does. The only procedure used from uCommonFunctions is resizeBitmap. Perhaps a good idea to replicate that inside unit VCL.Styles.DPIAware.pas ? – Gerrit Beuze Apr 26 '19 at 13:24