Added :DPI Scale for Windows XP,Vista,7,8 & 10 [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Added :DPI Scale for Windows XP,Vista,7,8 & 10 [Windows]

Post by RASHAD »

Hi
Very Simple
Tested but not too much

Code: Select all

If OSVersion() >= #PB_OS_Windows_7 And OSVersion() < #PB_OS_Windows_8 
  Global ScaleX.d = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) / 96
  Global ScaleY.d = GetDeviceCaps_(GetDC_(0),#LOGPIXELSY) / 96
  Debug ScaleX.d
  Debug ScaleY.d
ElseIf OSVersion() >= #PB_OS_Windows_8
  ExamineDesktops()
  h.WINDOWPLACEMENT
  GetWindowPlacement_(GetDesktopWindow_(),@h)
  Global ScaleX.d =  DesktopWidth(0) / h\rcNormalPosition\right
  Global ScaleY.d =  DesktopHeight(0) / h\rcNormalPosition\bottom
  Debug ScaleX.d
  Debug ScaleY.d
EndIf
Last edited by RASHAD on Tue Nov 07, 2017 7:52 am, edited 1 time in total.
Egypt my love
MarkOtt
User
User
Posts: 28
Joined: Sat Feb 11, 2017 8:33 pm
Location: Switzerland

Re: DPI Scale for Windows 7,8 & 10 [Windows]

Post by MarkOtt »

Hello RASHAD

According to my experience this cannot work for general. The GUI elements have to be scaled everytime, but not the fonts. Depending on the choosen Windows scaling settings sometimes the fonts have to be scaled, sometimes not.

Pleas see my post: http://www.purebasic.fr/english/viewtop ... 12&t=69570

Best regards. Markus

Edit (to clarify a little bit):
Using PB up to version 5.24 the fonts were scaled automatically correct without scaling them in the program. It was just enough to scale the other GUI elements.
Using PB version 5.45 (and 5.61) the things got more complicated:
Eg. in Windows 10, if I set 125% in the "fixed scaling dialog" (where I can choose 100%, 125%, 150%) then the fonts are not scaled automaticall by Windows, so I have to also scale the fonts in my program.
But Windows 10 scales the fonts automatically correct if I set 125% in the "user scaling dialog" (where it is possible to scale continuously). So Windows 10 font scaling is not behaving consistently, it depends on how it is set by the user. This is what my approach seems to solve (and it works also for Win 7 and 8 ).
Last edited by MarkOtt on Tue Nov 07, 2017 11:52 am, edited 1 time in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: DPI Scale for Windows 7,8 & 10 [Windows]

Post by RASHAD »

Next is an optimized version
No need to check which MS OS version are used
The aim of this post is the Scale nothing less nothing more
Is the scale all right or not
The Fonts are the coder responsibility
He/She should use his own font and do not rely on MS defaults

Code: Select all

  Global ScaleX1.d,ScaleY1.d,ScaleX2.d,ScaleY2.d,ScaleX.d,ScaleY.d

  ScaleX1 = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) / 96
  ScaleY1 = GetDeviceCaps_(GetDC_(0),#LOGPIXELSY) / 96
  ExamineDesktops()
  h.WINDOWPLACEMENT
  GetWindowPlacement_(GetDesktopWindow_(),@h)
  ScaleX2 =  DesktopWidth(0) / h\rcNormalPosition\right
  ScaleY2 =  DesktopHeight(0) / h\rcNormalPosition\bottom
  If ScaleX1 > ScaleX2
     ScaleX = ScaleX1
  Else
     ScaleX = ScaleX2
  EndIf
  If ScaleY1 > ScaleY2
     ScaleY = ScaleY1
  Else
     ScaleY = ScaleY2
  EndIf
  Debug ScaleX
  Debug ScaleY
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Added :DPI Scale for Windows XP,Vista,7,8 & 10 [Windows]

Post by RASHAD »

Added XP & Vista

Code: Select all

  Global ScaleX1.d,ScaleY1.d,ScaleX2.d,ScaleY2.d,ScaleX.d,ScaleY.d

  ScaleX1 = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) / 96
  ScaleY1 = GetDeviceCaps_(GetDC_(0),#LOGPIXELSY) / 96
  ExamineDesktops()
  h.WINDOWPLACEMENT
  GetWindowPlacement_(GetDesktopWindow_(),@h)
  ScaleX2 =  DesktopWidth(0) / h\rcNormalPosition\right
  ScaleY2 =  DesktopHeight(0) / h\rcNormalPosition\bottom
  If ScaleX1 > ScaleX2
     ScaleX = ScaleX1
  Else
     ScaleX = ScaleX2
  EndIf
  If ScaleY1 > ScaleY2
     ScaleY = ScaleY1
  Else
     ScaleY = ScaleY2
  EndIf
  If OSVersion() < #PB_OS_Windows_Vista
    ScaleX = ScaleX1
    ScaleY = ScaleY1
  EndIf
  Debug ScaleX
  Debug ScaleY
Egypt my love
Rothammel
New User
New User
Posts: 1
Joined: Tue Nov 07, 2017 5:53 pm

Re: Added :DPI Scale for Windows XP,Vista,7,8 & 10 [Windows]

Post by Rothammel »

RASHAD wrote:Added XP & Vista

Code: Select all

  Global ScaleX1.d,ScaleY1.d,ScaleX2.d,ScaleY2.d,ScaleX.d,ScaleY.d

  ScaleX1 = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) / 96
  ScaleY1 = GetDeviceCaps_(GetDC_(0),#LOGPIXELSY) / 96
  ExamineDesktops()
  h.WINDOWPLACEMENT
  GetWindowPlacement_(GetDesktopWindow_(),@h)
  ScaleX2 =  DesktopWidth(0) / h\rcNormalPosition\right
  ScaleY2 =  DesktopHeight(0) / h\rcNormalPosition\bottom
  If ScaleX1 > ScaleX2
     ScaleX = ScaleX1
  Else
     ScaleX = ScaleX2
  EndIf
  If ScaleY1 > ScaleY2
     ScaleY = ScaleY1
  Else
     ScaleY = ScaleY2
  EndIf
  If OSVersion() < #PB_OS_Windows_Vista
    ScaleX = ScaleX1
    ScaleY = ScaleY1
  EndIf
  Debug ScaleX
  Debug ScaleY
when I use this code with dpi aware statement in my executable manifest, it will not work. it gives every time 1.0 back
Post Reply