Recent

Author Topic: Question to High DPI - Window behaviore  (Read 643 times)

PeterX

  • Sr. Member
  • ****
  • Posts: 304
Question to High DPI - Window behaviore
« on: February 07, 2019, 04:31:42 pm »
Hi,

I currently work on an application - under MS WINDOWS - that creates a secondary Form/Window, on demand.
I want this Form/Window to move to the right of the screen, and resize to full screen height.

Since I switched on the "Hi DPI" feature it didn't behave as expected.
When resizing the secondary window in FormShow(Sender: TObject)
it got too large and bottom (and right) was outside the screen
( .. in case, Windows' Scaling is > 100% ).


Now I discovered again the "AfterShow" solution ..
=> https://www.swissdelphicenter.ch/de/showcode.php?id=1276

Now, when calling
Code: Pascal  [Select]
  1. PostMessage( Self.Handle, WM_AFTER_SHOW, 0, 0);
  2.  
in FormShow()

=>
Code: Pascal  [Select]
  1. procedure TSecondaryForm.WmAfterShow(var Msg: aMessage); //message WM_AFTER_SHOW;
  2. var
  3.   rNew : TRect;
  4.   r    : TRect;
  5. begin
  6.   GetWindowRect( FindWindow( 'Shell_traywnd', ''), r);
  7.   // needs JWAwindows in "uses"
  8.  
  9.   rNew.Top:= 0;
  10.   rNew.Left:= Screen.Width -Self.Width -1;
  11.   rNew.Right:= Screen.Width -1;
  12.   rNew.Bottom:= r.Top -48;
  13.   Self.BoundsRect:= rNew
  14. end;
  15.  
it much better fits to screen. Yeah !


Could this be called a "bug" or design error that the scaling of the window - with  Hi DPI -
(for example 125%) to the Screen Resolution
does happen after FormShow ?
« Last Edit: February 07, 2019, 04:34:01 pm by PeterX »
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

wp

  • Hero Member
  • *****
  • Posts: 5365
Re: Question to High DPI - Window behaviore
« Reply #1 on: February 07, 2019, 04:44:52 pm »
Well, Lazarus itself is a high-DPI application, and AFAIK it does not need such tricks. So I guess you are doing something in a way which is not correct for the LCL scaling. Please post a small project which shows the issue - without seeing any code it is very difficult to help.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

PeterX

  • Sr. Member
  • ****
  • Posts: 304
Re: Question to High DPI - Window behaviore
« Reply #2 on: February 07, 2019, 05:30:49 pm »
Please post a small project which shows the issue - without seeing any code it is very difficult to help.
Done.

But this example project does not show the misbehaviore ..  :(

I must say that my app is an old one, some years ago converted from a delphi 5 project.
Maybe there is some "hidden" setting that causes this issue ..  %)
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

ps

  • Jr. Member
  • **
  • Posts: 72
Re: Question to High DPI - Window behaviore
« Reply #3 on: February 07, 2019, 08:17:35 pm »
Well, Lazarus itself is a high-DPI application, and AFAIK it does not need such tricks. So I guess you are doing something in a way which is not correct for the LCL scaling.
But not on Win10 (with latest HighDPI or Per monitor, or changing dpi without logout (V2)).

Your code:
Code: Pascal  [Select]
  1. Self.BoundsRect:= rNew
calls:
Code: Pascal  [Select]
  1. SetBounds(ARect.Left, ARect.Top,
  2.     Max(ARect.Right - ARect.Left, 0), Max(ARect.Bottom - ARect.Top, 0));

Where before show width is 320  (Self.Width) and for example Width of screen is 2560  so Left will be 2240 and Right will be 2560 and SetBouds is called with (2240, 0, 320, screen.height). BUT! After form is shown up (DPI of designed width and height is changed) width and height will be scalled to current monitor DPI. And 320 (in 150%) will be 480 so and RIGHT position will be 2240 + 480 = 2720 -> so Offscreen! After form is shown it works correct (so no upscaling width and height value).

For left and right you can use:
Code: Pascal  [Select]
  1. Self.SetBounds(Screen.Width - MulDiv(Self.Width, Self.Monitor.PixelsPerInch, 96), 0, Self.Width, R.Bottom );
IDE:  Lazarus 1.8 RC3/Trunk, Delphi XE OS:Windows 10, Ubuntu

PeterX

  • Sr. Member
  • ****
  • Posts: 304
Re: Question to High DPI - Window behaviore
« Reply #4 on: February 11, 2019, 10:13:58 am »
For left and right you can use:
Code: Pascal  [Select]
  1. Self.SetBounds(Screen.Width - MulDiv(Self.Width, Self.Monitor.PixelsPerInch, 96), 0, Self.Width, R.Bottom );
  2.  
Hello ps, thanks for this example code, I will try it !

Because in my current solution (not in the sample code above, but in my application ..)
the second form pops up once, anywhere on the screen,
and then moves (jumps !) to the right of the screen - not good.

(Because atm I use this AfterShow event to scale and move the second form ..)
« Last Edit: February 11, 2019, 11:00:22 am by PeterX »
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job