Author Topic: _DESKTOPWIDTH and _DESKTOPHEIGHT won't update after program has started.  (Read 1813 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Stuart

  • Newbie
  • Posts: 11
I'm not sure if this is a bug or if it's by design but when a QB64 program first starts, _DESKTOPWIDTH and _DESKTOPHEIGHT both return the correct values for the desktop size...

...However, if the desktop resolution is changed _after_ the program has been started, _DESKTOPWIDTH and _DESKTOPHEIGHT still return the same values as they did when the program was first started.

Code: QB64: [Select]
  1. PRINT "The desktop resolution when this program was started    :";
  2.  
  3.  
  4.    PRINT
  5.    PRINT "Change to a different screen resolution and then"
  6.    PRINT "press <ENTER> to update the info...  ";
  7.    DO
  8.       _LIMIT 30
  9.    LOOP WHILE INKEY$ <> CHR$(13)
  10.    PRINT "current resolution :"; _DESKTOPWIDTH; "x"; _DESKTOPHEIGHT
  11.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: _DESKTOPWIDTH and _DESKTOPHEIGHT won't update after program has started.
« Reply #1 on: December 08, 2018, 05:50:42 am »
Desktopwidth is nearly a direct call to glutget(), and to be honest, I don’t know if this is the expected behavior or not. 

The documentation is very barebones: https://www.opengl.org/resources/libraries/glut/spec3/node70.html

GLUT_SCREEN_WIDTH
Width of the screen in pixels. Zero indicates the width is unknown or not available.
GLUT_SCREEN_HEIGHT
Height of the screen in pixels. Zero indicates the height is unknown or not available.


************

Now, whether that Width/Height is only calculated once at program start-up, or on the fly as needed, I honestly don’t know.

If your program requires detections for this type of thing, you may need to resort to using declare library with the windows api (or Linux/Mac equivalent).
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Stuart

  • Newbie
  • Posts: 11
Re: _DESKTOPWIDTH and _DESKTOPHEIGHT won't update after program has started.
« Reply #2 on: December 08, 2018, 09:54:21 am »
Now, whether that Width/Height is only calculated once at program start-up, or on the fly as needed, I honestly don’t know.

If your program requires detections for this type of thing, you may need to resort to using declare library with the windows api (or Linux/Mac equivalent).


Thanks for the quick response.

DECLARE LIBRARY and the Windows API are beyond my current programming capabilities...

It would be nice if Width/Height were calculated on the fly, but I can get by with it being calculated only at start-up since most people probably wouldn't be changing the screen resolution _after_ running a program anyway.

Marked as best answer by Stuart on December 09, 2018, 02:46:42 am

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: _DESKTOPWIDTH and _DESKTOPHEIGHT won't update after program has started.
« Reply #3 on: December 08, 2018, 12:29:05 pm »
Fooling around a little with Win API... I hope the wife doesn't find out. So, coincidence or does this code actually work...

Code: QB64: [Select]
  1.     FUNCTION GetSystemMetrics& (BYVAL Index AS _OFFSET)
  2.  
  3. xResult& = GetSystemMetrics&(0)
  4. yResult& = GetSystemMetrics&(1)
  5. PRINT xResult&; "x"; yResult&
  6.  

It seems to be good on mine, 1366 x 768 as checked in desktop properties for my current screen resolution.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Stuart

  • Newbie
  • Posts: 11
Re: _DESKTOPWIDTH and _DESKTOPHEIGHT won't update after program has started.
« Reply #4 on: December 09, 2018, 04:57:59 am »
Fooling around a little with Win API... I hope the wife doesn't find out. So, coincidence or does this code actually work...

Yes!  I added your code to the top of my sample program, made changes on two lines, and it works perfectly.

Now, if one of the developers could incorporate this into QB64.exe (at least for the Windows part of the code) then the _DESKTOPWIDTH and _DESKTOPHEIGHT commands would work a lot better.

Code: QB64: [Select]
  1.     FUNCTION GetSystemMetrics& (BYVAL Index AS _OFFSET)
  2.  
  3. REM xResult& = GetSystemMetrics&(0)
  4. REM yResult& = GetSystemMetrics&(1)
  5. REM PRINT xResult&; "x"; yResult&
  6.  
  7.  
  8.  
  9.  
  10.  
  11. PRINT "The desktop resolution when this program was started    :";
  12. '''''PRINT _DESKTOPWIDTH; "x"; _DESKTOPHEIGHT
  13. PRINT GetSystemMetrics&(0); "x"; GetSystemMetrics&(1)
  14.  
  15.  
  16.    PRINT
  17.    PRINT "Change to a different screen resolution and then"
  18.    PRINT "press <ENTER> to update the info...  ";
  19.    DO
  20.       _LIMIT 30
  21.    LOOP WHILE INKEY$ <> CHR$(13)
  22.    PRINT "current resolution :"; '''''_DESKTOPWIDTH; "x"; _DESKTOPHEIGHT
  23.    PRINT GetSystemMetrics&(0); "x"; GetSystemMetrics&(1)
  24.