WindowX/Y negative when maximized

Windows specific forum
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

WindowX/Y negative when maximized

Post by ozzie »

I'm trying to get the 'true' visible WindowX and WindowY of a maximized window, but I get small negative values. In a test program (see below) the negative values are -3, but in my own program I get -8. Any idea why they are negative and is there a Windows system metric value or something that corresponds to these offsets?

For example, in the following:

Code: Select all

If OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  Debug "(open) WindowX(0)=" + WindowX(0) + ", WindowY(0)=" + WindowY(0) + ", WindowWidth(0)=" + WindowWidth(0) + ", WindowHeight(0)=" + WindowHeight(0)
  
  Delay(2000)
  SetWindowState(0, #PB_Window_Maximize)
  Debug "(max) WindowX(0)=" + WindowX(0) + ", WindowY(0)=" + WindowY(0) + ", WindowWidth(0)=" + WindowWidth(0) + ", WindowHeight(0)=" + WindowHeight(0)
  
  Delay(2000)
  SetWindowState(0, #PB_Window_Normal)
  Debug "(normal) WindowX(0)=" + WindowX(0) + ", WindowY(0)=" + WindowY(0) + ", WindowWidth(0)=" + WindowWidth(0) + ", WindowHeight(0)=" + WindowHeight(0)
  
EndIf

I get the following debug messages:

Code: Select all

(open) WindowX(0)=100, WindowY(0)=200, WindowWidth(0)=195, WindowHeight(0)=260
(max) WindowX(0)=-3, WindowY(0)=-3, WindowWidth(0)=1366, WindowHeight(0)=716
(normal) WindowX(0)=100, WindowY(0)=200, WindowWidth(0)=195, WindowHeight(0)=260
My monitor size is 1366x768, but when the window is maximized WindowX(0) and WindowY(0) both return -3. Why don't they return 0?
User avatar
STARGÅTE
Addict
Addict
Posts: 2261
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: WindowX/Y negative when maximized

Post by STARGÅTE »

Use the parameter Mode:
http://purebasic.com/documentation/window/windowx.html
Mode (optional) The mode used to calculate the x position of the window. It can be one of the following value:
#PB_Window_FrameCoordinate: x position of the window, including borders (default).
#PB_Window_InnerCoordinate: x position of the window inner area (where gadget can be added), excluding borders.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: WindowX/Y negative when maximized

Post by IdeasVacuum »

It may also be related to how your Monitor is actually setup - the desktop itself could be slightly left and up, mine is slightly right and down.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: WindowX/Y negative when maximized

Post by ozzie »

STARGÅTE wrote:Use the parameter Mode:
http://purebasic.com/documentation/window/windowx.html
Thanks, but this gives different results again:

Code: Select all

(open) WindowX(0, #PB_Window_InnerCoordinate)=103, WindowY(0, #PB_Window_InnerCoordinate)=225, WindowWidth(0)=195, WindowHeight(0)=260
(max) WindowX(0, #PB_Window_InnerCoordinate)=0, WindowY(0, #PB_Window_InnerCoordinate)=22, WindowWidth(0)=1366, WindowHeight(0)=716
(normal) WindowX(0, #PB_Window_InnerCoordinate)=103, WindowY(0, #PB_Window_InnerCoordinate)=225, WindowWidth(0)=195, WindowHeight(0)=260
For the maximized window I do now get WindowX = 0 :D , but WindowY = 22 :( . For the normal window state, the window that was created at 100, 200 now returns 103, 225. Interesting that the X difference is 3, and my original WindowX(0) for the maximized window returned -3. So using #PB_Window_InnerCoordinate has added 3 to the Window X value, and 25 to the Window Y value. :?
IdeasVacuum wrote:It may also be related to how your Monitor is actually setup - the desktop itself could be slightly left and up, mine is slightly right and down.
That's possible, although I can't see how I can check or adjust that on the primary screen of my Toshiba laptop. But if the offset is due to how the monitor is set up, then the actual X and Y values returned may not matter for what I want to do.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: WindowX/Y negative when maximized

Post by PB »

> WindowX and WindowY of a maximized window, but I get small negative values

That's perfectly normal for Windows. The X and Y are indeed negative because
the window position, when maximized, is slightly off the top-left corner of the
monitor. Observe for yourself with a third-party app:

Image
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply