Problem With ResizeWindow and DPI Aware

Post bugreports for the Windows version here
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Problem With ResizeWindow and DPI Aware

Post by Paul »

In Windows 10 set your screen scaling to 125% or 150% and run this code with "DPI aware" turned on.
If I move the Main Window the others will stay locked with it. Now uncomment the "flag" line and run it again.
Now when I move the Main Window the others slowly wander off the screen. ?!?!?

(I only see this behavior when "DPI Aware" is on and the #PB_Window_SizeGadget flag is used)

Code: Select all

#Main=0
Global Dim w(3),x,y

Procedure Move()
  fixx=WindowX(#Main)-x 
  fixy=WindowY(#Main)-y
  x=WindowX(#Main)
  y=WindowY(#Main)
  For tmp=0 To 3
    ResizeWindow(w(tmp),WindowX(w(tmp))+fixx,WindowY(w(tmp))+fixy,#PB_Ignore,#PB_Ignore)
  Next
EndProcedure 


;flag=#PB_Window_SizeGadget  ;<------- test this line

If OpenWindow(#Main,0,0,900,300,"Main",#PB_Window_SystemMenu)
  For tmp=0 To 3
    w(tmp)=OpenWindow(#PB_Any,10+pos,50,200,150,"Win"+Str(tmp),flag,WindowID(Main))
    pos+210
  Next

  BindEvent(#PB_Event_MoveWindow,@Move(),#Main)
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Image Image
williamvanhoecke
User
User
Posts: 46
Joined: Wed Jun 07, 2017 10:13 pm

Re: Problem With ResizeWindow and DPI Aware

Post by williamvanhoecke »

Hello Paul,
I found your topic because I am having dpi troubles too.
I found out that also the ResizeGadget() is not working correctly IF two screens (monitors) have different DPI setting.

ResizeGadget() works correct if screen1 dpi = 100% and screen2 dpi = 100%
ResizeGadget() works correct if screen1 dpi = 125% and screen2 dpi = 125%
ResizeGadget() works correct if screen1 dpi = 150% and screen2 dpi = 150%

ResizeGadget() works NOT correct if screen1 dpi = 100% and screen2 dpi = 125%
ResizeGadget() works NOT correct if screen1 dpi = 1250% and screen2 dpi = 100%
etc...

So there is definitly something wrong with the dpi awareness, your code is proof
Just tested your code and indead the child windows wander off !!!

It is even worse when you use

fixx=WindowX(#Main,#PB_Window_InnerCoordinate)-x
fixy=WindowY(#Main,#PB_Window_InnerCoordinate)-y
williamvanhoecke
User
User
Posts: 46
Joined: Wed Jun 07, 2017 10:13 pm

Re: Problem With ResizeWindow and DPI Aware

Post by williamvanhoecke »

Fixed

Code: Select all

#Main=0
Global Dim w(3),x,y

Procedure Move()
  fixx=WindowX(#Main)-x
  fixy=WindowY(#Main)-y
  x=WindowX(#Main)
  y=WindowY(#Main)
  For tmp=0 To 3
    ResizeWindow(w(tmp),(WindowX(w(tmp))+fixx)/DesktopResolutionX(),WindowY(w(tmp))+fixy,#PB_Ignore,#PB_Ignore)
  Next
EndProcedure


;flag=#PB_Window_SizeGadget  ;<------- test this line

If OpenWindow(#Main,0,0,900,300,"Main",#PB_Window_SystemMenu)
  For tmp=0 To 3
    w(tmp)=OpenWindow(#PB_Any,10+pos,50,200,150,"Win"+Str(tmp),flag,WindowID(Main))
    pos+210
  Next

  BindEvent(#PB_Event_MoveWindow,@Move(),#Main)
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Problem With ResizeWindow and DPI Aware

Post by Paul »

williamvanhoecke wrote:Fixed
I'm guessing you either don't have "DPI Aware" enabled in compiler settings or you don't have Windows scaling set over 100% because your code shoots the Forms off the screen even faster than the original code when its compiled as "DPI Aware" ;)

Anyway I'm not looking for a bandaid I'm looking for it to be fixed internally.
If I want a bandaid I can just remove the resize flag on the Form, use the resize command then add the resize flag back every time an adjustment needs to be made.
Image Image
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Problem With ResizeWindow and DPI Aware

Post by Blue »

Problem confirmed, exactly as pointed out.

Nice find, Paul.

And since — to my knowledge anyway — you can't turn ON/OFF DPi awareness on the fly, the PB_Window_SizeGadget option remains unusable until the underlying bug is corrected.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Problem With ResizeWindow and DPI Aware

Post by Fred »

Fixed.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Problem With ResizeWindow and DPI Aware

Post by Paul »

Fred wrote:Fixed.
Just tested with PureBasic 5.73 LTS x64

Unfortunately this is only fixed on Windows 10.
If I run the above code on Windows 8 and Windows 7 at 150% Scaling, DPI Aware Enabled and #PB_Window_SizeGadget enabled, all the child windows head off the screen to the right.
Image Image
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Problem With ResizeWindow and DPI Aware

Post by Fred »

I only tested on Win10, I will take a closer look again
Post Reply