Please extend GetWindowState()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Please extend GetWindowState()

Post by Little John »

PurBasic has the command HideWindow(), but currently there is no corresponding native function that can determine whether or not a given window is hidden. So GetWindowState() should additionally have a possible return value such As #PB_Window_Hidden.
Quin
Addict
Addict
Posts: 1126
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Please extend GetWindowState()

Post by Quin »

+1
I do this in my app by holding an extra byte in my configuration structure that is #True if the window is shown, #false if it's hidden and I just set it manually, but being able to avoid this painful manual work with a native command would be much appreciated.
Ventural
User
User
Posts: 31
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa, FL
Contact:

Re: Please extend GetWindowState()

Post by Ventural »

Retrieves visibility state of window.

Code: Select all

Procedure.b IsHideWindow(WindowNum.q)
  If IsWindowVisible_(WindowID(WindowNum))
    ProcedureReturn #False ; 0 = Window is visible
  Else
    ProcedureReturn #True  ; 1 = Window is hidden
  EndIf
EndProcedure

If OpenWindow(0, 200, 200, 220, 100, "HideWindow()", #PB_Window_SystemMenu)
  ButtonGadget (1, 10, 60, 200, 30, "Hide the window")
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            HideWindow(0, #True)  
            Debug "Window hidden."
            Debug IsHideWindow(0)
            MessageRequester("Info", "Press OK to show the window")
            HideWindow(0, #False)  
            Debug "Window is visible."
            Debug IsHideWindow(0)
          EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
Quin
Addict
Addict
Posts: 1126
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Please extend GetWindowState()

Post by Quin »

Very nice, thanks! Would still love to see a native command, but I dropped this into my project and started using it, and it works flawlessly!
Ventural wrote: Mon Mar 10, 2025 5:34 am Retrieves visibility state of window.

Code: Select all

Procedure.b IsHideWindow(WindowNum.q)
  If IsWindowVisible_(WindowID(WindowNum))
    ProcedureReturn #False ; 0 = Window is visible
  Else
    ProcedureReturn #True  ; 1 = Window is hidden
  EndIf
EndProcedure

If OpenWindow(0, 200, 200, 220, 100, "HideWindow()", #PB_Window_SystemMenu)
  ButtonGadget (1, 10, 60, 200, 30, "Hide the window")
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            HideWindow(0, #True)  
            Debug "Window hidden."
            Debug IsHideWindow(0)
            MessageRequester("Info", "Press OK to show the window")
            HideWindow(0, #False)  
            Debug "Window is visible."
            Debug IsHideWindow(0)
          EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Please extend GetWindowState()

Post by Marc56us »

Would still love to see a native command
Yes.
In the meantime, to keep things simple, just one line is enough:

Code: Select all

IsWindowVisible_( WindowID( 0 ) )
Return
0 = hidden
1 = Visible
Quin
Addict
Addict
Posts: 1126
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Please extend GetWindowState()

Post by Quin »

Marc56us wrote: Mon Mar 10, 2025 3:51 pm
Would still love to see a native command
Yes.
In the meantime, to keep things simple, just one line is enough:

Code: Select all

IsWindowVisible_( WindowID( 0 ) )
Return
0 = hidden
1 = Visible
How's this one?

Code: Select all

Macro IsWindowHidden(_Window) : Not IsWindowVisible_(WindowID(_Window)) : EndMacro
:)
Only sad thing is it's windows only.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please extend GetWindowState()

Post by Little John »

Ventural wrote: Mon Mar 10, 2025 5:34 am

Code: Select all

  If IsWindowVisible_(WindowID(WindowNum))
I know the Windows API function IsWindowVisible_().
However, having a cross-platform native PureBasic function for this would make sense IMHO.
Post Reply