[SOLVED] How to check if gadget is visible or not?

Just starting out? Need help? Post your questions and find answers here.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

[SOLVED] How to check if gadget is visible or not?

Post by SkyManager »

Hi, does anybody know how to check if a gadget is visible or not?
Last edited by SkyManager on Thu Aug 08, 2019 6:18 am, edited 1 time in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: How to check if gadget is visible or not?

Post by RSBasic »

Code: Select all

EnableExplicit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10, 10, 100, 20, "Button 1", 0)
  ButtonGadget(2, 10, 40, 100, 20, "Button 2", 0)
  
  HideGadget(1, 1)
  
  If IsWindowVisible_(GadgetID(1)) = 1
    Debug "Button 1 is visible"
  Else
    Debug "Button 1 is hidden"
  EndIf
  
  If IsWindowVisible_(GadgetID(2)) = 1
    Debug "Button 2 is visible"
  Else
    Debug "Button 2 is hidden"
  EndIf
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Image
Image
mestnyi
Addict
Addict
Posts: 1103
Joined: Mon Nov 25, 2013 6:41 am

Re: How to check if gadget is visible or not?

Post by mestnyi »

multi os

Code: Select all

DeclareModule Hide
  Declare.b Hide(Handle.i)
EndDeclareModule

Module Hide
  CompilerSelect #PB_Compiler_OS 
    CompilerCase #PB_OS_Linux
      ImportC ""
        gtk_widget_get_visible(*widget.GtkWidget)
      EndImport
  CompilerEndSelect
  
  Procedure.b Hide(Handle.i) ; Returns TRUE is control hide
    Protected Result.i
    
    CompilerSelect #PB_Compiler_OS 
      CompilerCase #PB_OS_Windows : ProcedureReturn Bool(IsWindowVisible_(Handle)=0)
      CompilerCase #PB_OS_Linux   : ProcedureReturn Bool(gtk_widget_get_visible(Handle)=0)
      CompilerCase #PB_OS_MacOS   
        CocoaMessage(@Result, CocoaMessage(0, handle, "className"), "UTF8String")
        
        If PeekS(Result, -1, #PB_UTF8) = "PBWindow"
          ProcedureReturn Bool(CocoaMessage(0, Handle, "isVisible")=0)
        Else
          ProcedureReturn Bool(CocoaMessage(0, Handle, "isHidden"))
        EndIf
    CompilerEndSelect
  EndProcedure
EndModule


CompilerIf #PB_Compiler_IsMainFile
; Shows possible flags of ButtonGadget in action...
  If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
    ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
    ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
    ButtonGadget(3, 10,100, 200, 60, "Multiline Button  (longer text gets automatically wrapped)", #PB_Button_MultiLine)
    ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
    
    HideGadget(1,1)
    ; HideWindow(0,1)
    Debug Hide::Hide(WindowID(0)) ; CocoaMessage (0, WindowID (0), "isVisible")
    Debug Hide::Hide(GadgetID(1))
    Debug Hide::Hide(GadgetID(2))
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
CompilerEndIf
Post Reply