curious display behavioural

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 335
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

curious display behavioural

Post by morosh »

Hello:
I'm writing a program and I need that the height of the main window to be the full height just above the taskbar by 3 pixels (I like to see the lower edge), and I have two laptops with different scales, so I need support for scale also, I tried the following, it works well only when I substract twice the taskbar height not once (in this case the lower part is hidden), which is curious, unless there is something wrong on my system.
Any help is appreciated.
my display is 17": 1600*900, scale=1.2 and 1, using W10, PB6.11

Code: Select all

EnableExplicit

Define kx.d, ky.d, DesktopRect.RECT, wid.u, hei.u
Define top.u, bottom.u, left.u, right.u, taskbar.u
Define heiw.u, widw.u

kx=1/DesktopResolutionX()
ky=1/DesktopResolutionY()

ExamineDesktops()
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @DesktopRect.RECT, 0)
left= DesktopRect\left
top= DesktopRect\top
right= DesktopRect\right
bottom= DesktopRect\bottom

wid=DesktopWidth(0)
hei=DesktopHeight(0)

Debug wid
Debug hei

Debug left
Debug top
Debug right
Debug bottom
taskbar=hei-bottom
Debug taskbar

widw=0.5*wid*kx
;heiw=(hei-2*taskbar)*ky-3   ; this is good
heiw=(hei-taskbar)*ky-3   ; this is bad

OpenWindow(0,left*kx,0,widw,heiw,"Test",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)

Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
CloseDebugOutput()
PureBasic: Surprisingly simple, diabolically powerful
Axolotl
Addict
Addict
Posts: 873
Joined: Wed Dec 31, 2008 3:36 pm

Re: curious display behavioural

Post by Axolotl »

hi morosh,

I am pretty sure you know this:
Remarks The application needs to be compiled with the 'DPI Aware' switch to have this command returning real DPI resolution factor. If not, the result will be always be '1'.


You are using the #SPI_GETWORKAREA which returns the correct screen area (w/o taskbar). Why not using this for OpenWindow().
You can use some macros like:

Code: Select all

Macro RectWidth(R) 
  ((R\right) - (R\left)) 
EndMacro 

Macro RectHeight(R)
  ((R\bottom) - (R\top)) 
EndMacro 
In your case it is probably necessary to use the DesktopScaledX(Value) and DesktopScaledY(Value) functions. as well.
BTW: I only use Scale == 1.00 so I cannot say anything about these functions. The SystemParameterInfo_ functions works for me all time long.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
morosh
Enthusiast
Enthusiast
Posts: 335
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: curious display behavioural

Post by morosh »

Yes, I'm compiling with dpi aware option.
OpenWindow Maximized don't suit me, because I want half the desktop width and near (-3 pixels) full the desktop Height.
using DesktopScaledX(Value) is equivalent to kx=1/DesktopResolutionX(), etc...

with my posted program, did you get the lower edge visible?
PureBasic: Surprisingly simple, diabolically powerful
Axolotl
Addict
Addict
Posts: 873
Joined: Wed Dec 31, 2008 3:36 pm

Re: curious display behavioural

Post by Axolotl »

hi morosh,

weird.
I changed your main loop to this:

Code: Select all

Define WindowRect.RECT  ; <-- on top 
Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow
      Break 

    Case #PB_Event_LeftClick 
      Debug "Window() == " + WindowX(0) + ", " + WindowY(0) + ", " + WindowHeight(0) + ", " + WindowWidth(0)

      GetWindowRect_(WindowID(0), @WindowRect) 
      Debug "Rect = " + WindowRect\left + "," + WindowRect\top + ", " + WindowRect\right + ", " + WindowRect\bottom 

    Case #PB_Event_RightClick 
;     SetWindowPos_(WindowID(0), 0, DesktopRect\left, DesktopRect\top, DesktopRect\right/2, DesktopRect\bottom, #SWP_NOZORDER|#SWP_NOSENDCHANGING) 
      SetWindowPos_(WindowID(0), 0, DesktopRect\left, DesktopRect\top, widw, DesktopRect\bottom, #SWP_NOZORDER|#SWP_NOSENDCHANGING) 
      
  EndSelect
ForEver 
1. Click with left mouse you see the different window parameter PB and Win.
2. Click right to replace the window with system function. (this works on my computer)
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
morosh
Enthusiast
Enthusiast
Posts: 335
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: curious display behavioural

Post by morosh »

it seems that SetWindowPos_ dont take scale into account.
I changed Case #PB_Event_LeftClick as follow:
Debug "Window() == " + WindowX(0) + ", " + WindowY(0) + ", " + WindowWidth(0) + ", " + WindowHeight(0)
to have like x, y, w, h convention.

Anyway, I can live with
heiw=(hei-2*taskbar)*ky-3 ;
but still a curious notice.

Thanks
PureBasic: Surprisingly simple, diabolically powerful
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: curious display behavioural

Post by boddhi »

morosh wrote: it seems that SetWindowPos_ dont take scale into account.
Hi,

Is there a link with this Fred's non-detailed comment?
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply