QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on March 22, 2021, 05:16:57 pm

Title: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: hanness on March 22, 2021, 05:16:57 pm
My laptop has a display resolution of 3840 x 2160, but when I run the code below it returns a display width of 1920 and a display height of 1080:

Option _Explicit
Dim As Integer x, y
' image& = _ScreenImage
x = _DesktopWidth
y = _DesktopHeight
Print x; y

Tested on Win 10, 20H2 with QB64 1.5
Title: Re: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: SMcNeill on March 22, 2021, 05:28:05 pm
It’s because you have windows scaling at 200%.

Set scale to 100% and you’ll get the full resolution.
Title: Re: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: SpriggsySpriggs on March 22, 2021, 08:52:35 pm
@hanness This is because QB64 programs are not DPI aware. I made a pull request on GitHub to fix a different issue that still is tied to yours that allows QB64 programs to be DPI aware. This should allow you to have full 3840 x 2160 even when at 200% resolution.
Title: Re: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: SpriggsySpriggs on March 22, 2021, 10:35:09 pm
Try running the below code with your scaling at 200% and see if you get the right results:

Code: QB64: [Select]
  1.  
  2. Type RECT
  3.     As Long left, top, right, bottom
  4.  
  5.     Function SetProcessDPIAware%% ()
  6.  
  7.     Function SetProcessDpiAwareness%& (ByVal value As Long)
  8.  
  9.     Function GetDesktopWindow%& ()
  10.     Function GetWindowRect%% (ByVal hWnd As _Offset, Byval lpRect As _Offset)
  11.     Function GetClientRect%% (ByVal hWnd As _Offset, Byval lpRect As _Offset)
  12.  
  13. 'Print SetProcessDPIAware 'You can uncomment this one and comment out the other if you want. Both do the same thing.
  14. Print SetProcessDpiAwareness(1)
  15.  
  16. Dim As _Offset desktop
  17. Dim As RECT rect, rect2
  18. desktop = GetDesktopWindow
  19. If desktop Then
  20.     If GetWindowRect(desktop, _Offset(rect)) Then
  21.         Print rect.left, rect.top, rect.right, rect.bottom
  22.         If GetClientRect(desktop, _Offset(rect2)) Then
  23.             Print rect2.left, rect2.top, rect2.right, rect2.bottom
  24.         End If
  25.     End If
Title: Re: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: hanness on March 23, 2021, 01:00:07 am
Thanks much. That makes sense, and the code provided did indeed work.

As always, the help was very appreciated.
Title: Re: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: SpriggsySpriggs on March 23, 2021, 09:20:06 am
@hanness Awesome! Glad it worked for you. Your problem and LM's are both good examples to show that DPI awareness is needed in QB64.
Title: Re: What are the limits for _DesktopWidth and _DesktopHeight?
Post by: SpriggsySpriggs on March 24, 2021, 12:46:12 pm
@hanness The latest dev build has the bug fix and automatically makes the program DPI aware. Download at your convenience and let us know how it goes for you.