It is currently Mon Oct 14, 2019 4:16 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 3:42 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 325
Foreword: I'm using a single monitor at 125% DPI for this test.

Have a look at this code. What I want to do is center any given window (even third-party) on the desktop. But if I use ExamineDesktops() and DesktopWidth()/DesktopHeight() to do the calculations, the window does NOT get centered. It only gets centered if I use the Windows API call of GetSystemMetrics_().

The simple, foolproof, standalone code and screenshot below explain everything. Shouldn't DesktopWidth()/DesktopHeight() match what GetSystemMetrics_() returns? Is this a bug?

As you can see with your own eyes, I simply cannot rely on DesktopWidth()/DesktopHeight() at all for 125% DPI (or higher) displays. :(

Code:
; Set your monitor to 125% DPI first!

gsm_W=GetSystemMetrics_(#SM_CXSCREEN)
gsm_H=GetSystemMetrics_(#SM_CYSCREEN)
Debug gsm_W ; 1024
Debug gsm_H ; 819

ExamineDesktops()
ed_W=DesktopWidth(0)
ed_H=DesktopHeight(0)
Debug ed_W ; 1280
Debug ed_H ; 1024

w=500
h=250
OpenWindow(1,0,0,w,h,"GetSystemMetrics",#PB_Window_SystemMenu)
ResizeWindow(1,(gsm_W-w)/2,(gsm_H-h)/2,#PB_Ignore,#PB_Ignore)

OpenWindow(2,0,0,w,h,"ExamineDesktops",#PB_Window_SystemMenu)
ResizeWindow(2,(ed_W-w)/2,(ed_H-h)/2,#PB_Ignore,#PB_Ignore)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Image


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 4:05 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3414
Using PB 5.7 with DPI enabled both results are identical

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 4:20 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 325
RASHAD wrote:
Using PB 5.7 with DPI enabled both results are identical

Not here (using 5.71 beta 1) with a 125% DPI monitor. When I enable DPI in the Compiler Options, both sets of variables still have different results, and the windows are now centered opposite: that is, the ExamineDesktops window is centered, but the GetSystemMetrics window is off-center (opposite to what my screenshot shows). What the hell.

So, I guess we should just enable DPI for our apps and use DesktopWidth()/DesktopHeight() then? Why is DPI even an option?


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 4:56 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3414
Hi Barry :P
No one can solve the DPI problems but you
For me I use Per Monitor Aware through the registry
And when I want a different scale I do it programmatic
Search the forum for a good example by Danilo

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 8:13 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3669
Location: Berlin, Germany
BarryG wrote:
Is this a bug?

Yes, and it has already been fixed for the next version of PB 5.71:
viewtopic.php?f=4&t=72833

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 8:33 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 441
Not only ! It is not only a bug ! Do not forget the window borders.

Code:
X = (DesktopWidth(0) - WindowWidth(Window, #PB_Window_FrameCoordinate) ) / 2
Y = (DesktopHeight(0) - WindowHeight(Window, #PB_Window_FrameCoordinate) ) / 2
ResizeWindow(Window, X, Y, #PB_Ignore, #PB_Ignore)

When we set a window size in OpenWindow(), we specify the window inner size, not the window total size.


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 8:33 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 325
Good to know, Little John. Thanks for the link.


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 8:34 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 325
Olliv wrote:
Do not forget the window borders.

I know, but including the borders still makes it way off-center. (They only add about 7 pixels on each window side).


Top
 Profile  
Reply with quote  
 Post subject: Re: DesktopWidth()/DesktopHeight() unreliable?
PostPosted: Sun Jun 09, 2019 8:44 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 441
7 pixels on your specific theme, what it can changes. And 7 pixels for the width. For the height, it is more, including title bar (near 24 pixels).

If you can check if WindowWidth() and WindowHeight() in the both modes (inner mode and frame mode) have the right values with and without DPI aware. I am not sure they are perfect.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: W4GNS and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye