Bug or Feature: WindowX() / WindowY()

Just starting out? Need help? Post your questions and find answers here.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Bug or Feature: WindowX() / WindowY()

Post 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?
Tranquil
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Sparkie that is fantastic! :D much neater than I do it!!!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks Rook :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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!!
Tranquil
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

Sparkie: Many thanks.
You are a fountain of API surprises!
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're welcome guys, and thank you both for the kind words. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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)?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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)?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

The program runs from the system tray (a.k.a. System notification area) .
:roll:
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

:roll:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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:
Post Reply