vcl-styles-utils icon indicating copy to clipboard operation
vcl-styles-utils copied to clipboard

Problem with Form/Window Caption on HIGH DPI, Delphi 10.3 and VCLStyles SKIN

Open ivancx opened this issue 6 years ago • 6 comments

Please look at the issue with Form caption, high DPI and Delphi 10.3.

https://stackoverflow.com/questions/55539396/problem-with-form-window-caption-on-high-dpi-delphi-10-3-and-vclstyles-skin

ivancx avatar Apr 06 '19 06:04 ivancx

I think I fixed this issue in /Common/Vcl.Styles.DPIAware.pas found at https://github.com/salvadordf/vcl-styles-utils. Please download and try it. Let me know if it works or not. Don't forget to read the instructions, at the top of the Vcl.Styles.DPIAware.pas file, on how to use it.

Regards, Rickard Johansson

rickard67 avatar Apr 20 '19 11:04 rickard67

Rickard,

Have you uploaded new file (last available is 26 days old which I use in my previous check) / and doesn't have anything at top on how to use it...

ivancx avatar Apr 22 '19 06:04 ivancx

The file Vcl.Styles.DPIAware.pas should contain the following:

{ Modified 20-Mar-2019 by Rickard Johansson (www.rj-texted.se). Purpose: Add per-monitor DPI awareness Usage: Add the unit to the interface uses statement of the main form and add code below:

TMyForm = class(TForm) private FStyleDPIAwareness : TStyleDPIAwareness;

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

procedure TFrmMain.FormDestroy(Sender: TObject); begin FStyleDPIAwareness.Free;

procedure TFrmMain.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer); begin FStyleDPIAwareness.AfterDPIChange(OldDPI, NewDPI); end;

procedure TFrmMain.FormBeforeMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer); begin FStyleDPIAwareness.BeforeDPIChange(OldDPI, NewDPI); end; }

I haven't updated the file in the salvadordf repository. It should work as it is.

rickard67 avatar Apr 22 '19 07:04 rickard67

Caption is now with correct size (height) but font is still ugly - too high and bold. Is there any way we can set custom font for Window Caption in skin on runtime - as we can for form font?

ivancx avatar Apr 26 '19 09:04 ivancx

It's not easy to fix. Let's hope Embarcadero will fix this in a later version.

You could copy the Vcl.Form.pas file to your project folder and modify it.

Look for the procedure:

procedure TFormStyleHook.PaintNC(Canvas: TCanvas);

and find the lines:

StyleServices.DrawText(CaptionBuffer.Canvas.Handle, CaptionDetails, LText, TextRect, TextFormat, clNone, PPI);
if FStretchedCaptionInc > 0 then
  MoveWindowOrg(CaptionBuffer.Canvas.Handle, 0, -TextTopOffset);

at the end of the procedure. Change it to something like this:

CaptionBuffer.Canvas.Font.Name := Form.Font.Name;
CaptionBuffer.Canvas.Font.Size := Form.Font.Size;
SetBkMode(CaptionBuffer.Canvas.Handle, TRANSPARENT);
DrawText(CaptionBuffer.Canvas.Handle, PChar(LText), Length(LText), TextRect, DT_VCENTER or DT_SINGLELINE or DT_LEFT or DT_NOPREFIX or DT_NOCLIP);
//StyleServices.DrawText(CaptionBuffer.Canvas.Handle, CaptionDetails, LText, TextRect, TextFormat, clNone, PPI);
if FStretchedCaptionInc > 0 then
  MoveWindowOrg(CaptionBuffer.Canvas.Handle, 0, -TextTopOffset);

rickard67 avatar Apr 26 '19 13:04 rickard67

Greatly appreciate your help @rickard67 !!!

spwolf avatar Apr 30 '19 18:04 spwolf