Author Topic: What are the limits for _DesktopWidth and _DesktopHeight?  (Read 3595 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
What are the limits for _DesktopWidth and _DesktopHeight?
« 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

Marked as best answer by hanness on March 22, 2021, 09:00:28 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: What are the limits for _DesktopWidth and _DesktopHeight?
« Reply #1 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: What are the limits for _DesktopWidth and _DesktopHeight?
« Reply #2 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.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: What are the limits for _DesktopWidth and _DesktopHeight?
« Reply #3 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
Shuwatch!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: What are the limits for _DesktopWidth and _DesktopHeight?
« Reply #4 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.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: What are the limits for _DesktopWidth and _DesktopHeight?
« Reply #5 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.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: What are the limits for _DesktopWidth and _DesktopHeight?
« Reply #6 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.
Shuwatch!