Page 1 of 2

Bug or Feature: WindowX() / WindowY()

Posted: Thu Apr 17, 2008 5:56 am
by Tranquil
I noticed that WindowX() and WindowY() returning negative values if window is minimized. Is this a Windows-Only thingie or cross-over behavior?

Is there a way to get the original window-dimensions even if the window is minimized?

Posted: Thu Apr 17, 2008 6:54 am
by Mistrel

Posted: Thu Apr 17, 2008 3:32 pm
by Rook Zimbabwe
I usually just keep 4 variables: oldx, oldy, oldxx, oldyy but I haven't had to do this with more than 1 window.

It appears you cannot set data into the window gadget like you can with other gadgets... maybe you could store the window locations in 4 gadgets in that window?

8)

Posted: Fri Apr 18, 2008 3:52 am
by Sparkie

Code: Select all

Procedure.l sp_GetDefaultRect(hwnd, *rc.RECT)
  GetWindowPlacement_(hwnd, @wp.WINDOWPLACEMENT)
  *rc\left = wp\rcNormalPosition\left
  *rc\top = wp\rcNormalPosition\top
  *rc\right = wp\rcNormalPosition\right
  *rc\bottom = wp\rcNormalPosition\bottom
  ProcedureReturn *rc
EndProcedure

Procedure.l EnumWindowsProc(hwnd, lParam) 
  If hwnd 
    If IsWindowVisible_(hwnd) 
      st$ = Space(256) 
      GetWindowText_(hwnd, @st$, 256) 
      If st$ 
        sp_GetDefaultRect(hwnd, @winRc.RECT) 
        AddGadgetItem(1, -1, st$ + Chr(10) + Str(winRc\left) + Chr(10) + Str(winRc\top) + Chr(10) + Str(winRc\right) + Chr(10) + Str(winRc\bottom) + Chr(10) + Str(winRc\right - winRc\left) + Chr(10) + Str(winRc\bottom - winRc\top)) 
      EndIf 
    EndIf 
    result = #True 
  Else 
    result = #False 
  EndIf 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0, 10, 10, 800, 500, "Sparked Window Rect", #PB_Window_ScreenCentered | #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0)) 
  TextGadget(0, 10, 10, 780, 30, "These values indicate the default normal (non-maximized) coordinates of each window.") 
  ListIconGadget(1, 10, 50, 780, 440, "Window", 480, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect) 
  AddGadgetColumn(1, 1, "Left", 50) 
  AddGadgetColumn(1, 2, "Top", 50) 
  AddGadgetColumn(1, 3, "Right", 50) 
  AddGadgetColumn(1, 4, "Bottom", 50) 
  AddGadgetColumn(1, 5, "Width", 50) 
  AddGadgetColumn(1, 6, "Height", 50) 
  EnumWindows_(@EnumWindowsProc(), 0) 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
EndIf

Posted: Fri Apr 18, 2008 8:00 pm
by Rook Zimbabwe
Sparkie that is fantastic! :D much neater than I do it!!!

Posted: Sat Apr 19, 2008 2:32 am
by Sparkie
Thanks Rook :)

Posted: Sat Apr 19, 2008 6:22 am
by Tranquil
Hi Sparkie!

Thanks for that code! So I dont need to unIconify my windows first, before getting the window dimensions and saving positions to disc.

Nice work!!

Posted: Sat Apr 19, 2008 12:52 pm
by einander
Sparkie: Many thanks.
You are a fountain of API surprises!

Posted: Sun Apr 20, 2008 12:52 am
by Sparkie
You're welcome guys, and thank you both for the kind words. :)

Posted: Sun Apr 20, 2008 4:14 am
by Demivec
I tested your code on my system. For one particular program I received these values:

Code: Select all

Left:-1476,Top:-1580,Right:-1020,Bottom:-1346,Width:456,Height:234
The program runs from the system tray (a.k.a. System notification area) . So it would seem that negative coordinates are still possible. I was just wondering how to interpret this information. Or to put it another way, when would the cordinates be negative for a program's window (using the code you provided)?

Posted: Sun Apr 20, 2008 4:34 am
by Sparkie
I have a dual monitor setup, with my main monitor(1) on the right and secondary monitor(2) on the left. This causes any and all windows on monitor 2 to have negative left/right values.

Another thought that comes to mind is maybe the developer is using it as a way to hide the window.

Using the hwnd from the EnumWindowsProc() in my code, maybe you can move the window into view with MoveWindow_(hwnd, 0, 0, width, height)?

Posted: Sun Apr 20, 2008 4:56 am
by Mistrel
The program runs from the system tray (a.k.a. System notification area) .
:roll:

Posted: Sun Apr 20, 2008 5:03 am
by Sparkie
:roll:

Posted: Sun Apr 20, 2008 7:42 am
by Demivec
Mistrel wrote:
The program runs from the system tray (a.k.a. System notification area) .
:roll:
Words would help explain what you mean but I'll take a stab at it anyway.

The program does display a window upon request. When the window is displayed it has the dimensions that were reported by Sparkie's code. I also ran Sparkie's code after displaying the window and it still reported the co-ordinates as negative values. I had naively thought if I displayed the window it would report positive values instead, which it didn't.

@Sparkie: I am using only a single monitor setup. I'll get back to you on what happens by attempting to move the window into positive territory.

Posted: Sun Apr 20, 2008 6:43 pm
by Demivec
Sparkie wrote:Another thought that comes to mind is maybe the developer is using it as a way to hide the window.

Using the hwnd from the EnumWindowsProc() in my code, maybe you can move the window into view with MoveWindow_(hwnd, 0, 0, width, height)?
@Sparkie: I have tried your suggestion and here are my results.

The window that became visible for the program in question was it's "About" window. When that menu option is selected for the program it adds 2048 to the x,y co-ordinates to show the window then adds a few buttons to it as well. It subtracts 2048 from the x,y co-ordinates to hide it again.8)

So your first idea seems to be correct, that it is being hidden by making it's coordinates negative.

Thanks for your input. :wink: