Page 1 of 1

Please extend GetWindowState()

Posted: Sat Mar 01, 2025 4:55 pm
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.

Re: Please extend GetWindowState()

Posted: Sat Mar 01, 2025 5:15 pm
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.

Re: Please extend GetWindowState()

Posted: Mon Mar 10, 2025 5:34 am
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

Re: Please extend GetWindowState()

Posted: Mon Mar 10, 2025 2:34 pm
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

Re: Please extend GetWindowState()

Posted: Mon Mar 10, 2025 3:51 pm
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

Re: Please extend GetWindowState()

Posted: Mon Mar 10, 2025 4:24 pm
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.

Re: Please extend GetWindowState()

Posted: Mon Mar 10, 2025 5:20 pm
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.