Is gadget hidden or not?

Just starting out? Need help? Post your questions and find answers here.
IgglePiggle
New User
New User
Posts: 6
Joined: Sun Jul 06, 2008 6:54 am
Location: Manchester, UK

Is gadget hidden or not?

Post by IgglePiggle »

Can anyone tell me how to detect in my code if a gadget has been hidden with HideGadget ?

I've tried this:

Code: Select all

IsWindowVisible_(GadgetID(#YourGadget))
(recommended somewhere else on the forum) but no luck so far!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Is gadget hidden or not?

Post by PB »

Hello, IgglePiggle! :) The code you posted works fine. If it's not working for
you, then please post a snippet that shows it failing, so we can see what
you're doing wrong.
IgglePiggle
New User
New User
Posts: 6
Joined: Sun Jul 06, 2008 6:54 am
Location: Manchester, UK

Post by IgglePiggle »

Thanks for the reply...

I still can't get this working, I must be doing something wrong.

cg is set to a valid gadget #

Code: Select all

HideGadget(cg,0)
Debug "BEFORE:"+Str(IsWindowVisible_(GadgetID(cg)))
HideGadget(cg,1)
Debug "AFTER"+Str(IsWindowVisible_(GadgetID(cg)))
gives me:

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

Post by Rook Zimbabwe »

Result = IsGadget(#YourGadget) = test to see if inistialized but it only returns internal ID

GetgadgetState(#Button) returns 0 each time no matter what the status is

look:

Code: Select all


Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Text_2
  #Text_1
  #Text_0
  #Button_2
  #Button_1
  #Button_0
EndEnumeration

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()

Procedure Button_2_Event(Window, Event, Gadget, Type)
  Debug "#Button_2"
EndProcedure

Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
EndProcedure

Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
EndProcedure

Procedure RegisterGadgetEvent(Gadget, *Function)
  
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
  
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
  
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
      LastElement(EventProcedures())
    EndIf
  Next
  
EndProcedure

Procedure Open_Window_0()
  
  If OpenWindow(#Window_0, 5, 5, 400, 268, "Window 0",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      ButtonGadget(#Button_0, 15, 15, 365, 45, "BUTTON 0 is VISIBLE and NOT HIDDEN")
      RegisterGadgetEvent(#Button_0, @Button_0_Event())
      ButtonGadget(#Button_1, 15, 70, 365, 45, "BUTTON 1 is DISABLED")
      RegisterGadgetEvent(#Button_1, @Button_1_Event())
      ButtonGadget(#Button_2, 15, 125, 365, 45, "BUTTON 2 is INVISIBLE")
      RegisterGadgetEvent(#Button_2, @Button_2_Event())
      TextGadget(#Text_0, 20, 180, 355, 20, "", #PB_Text_Center | #PB_Text_Border)
      TextGadget(#Text_1, 20, 205, 355, 20, "", #PB_Text_Center | #PB_Text_Border)
      TextGadget(#Text_2, 20, 230, 355, 20, "", #PB_Text_Center | #PB_Text_Border)

    EndIf
  EndIf
EndProcedure

Open_Window_0()

DisableGadget(#Button_1, 1); button 1 is now dsiabled
DisableGadget(#Button_2, 1) ; button 2 is now disabled
HideGadget(#Button_2, 1); button 2 is now hidden

Result0 =  GetGadgetState(#Button_0)
SetGadgetText(#Text_0, "BUTTON 0 STATE = "+Str(Result0))

Result1 =  GetGadgetState(#Button_1)
SetGadgetText(#Text_1, "BUTTON 1 STATE = "+Str(Result1))

Result2 =  GetGadgetState(#Button_2) 
SetGadgetText(#Text_2, "BUTTON 2 STATE = "+Str(Result2))

Repeat
  
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
  
  Select Event
    Case #PB_Event_Gadget
      CallEventFunction(Window, Event, Gadget, Type)
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
?

OK my only workaround theory is:

Set button text to "" (nothing) and use Getgadgettext() to see if the button has no text that will check for disabled buttons or inactive buttons! :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

works for me:

Code: Select all

If OpenWindow(0, 369, 199, 229, 74, "Test")
  If CreateGadgetList(WindowID(0))
    cg=StringGadget(#PB_Any, 30, 20, 180, 30, "")
    
  EndIf
EndIf

HideGadget(cg, 0)
Debug "BEFORE: "+Str(IsWindowVisible_(GadgetID(cg))) 
HideGadget(cg, 1)
Debug "AFTER: "+Str(IsWindowVisible_(GadgetID(cg)))
PureBasic for Windows
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@IgglePiggle: Your second bit of code doesn't show a failing snippet... so we
still can't see what you're doing wrong. How can we help in such a case?
IgglePiggle
New User
New User
Posts: 6
Joined: Sun Jul 06, 2008 6:54 am
Location: Manchester, UK

Post by IgglePiggle »

PB wrote:@IgglePiggle: Your second bit of code doesn't show a failing snippet...
OK so the debug window is not supposed to show a 0 then a 1? (in my example)

am I misunderstanding what values should be returned?

If you guys are saying it works, presumably you mean you are getting 0 then 1 in the above test?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

Here's the debug output:

Code: Select all

BEFORE: 1
AFTER: 0
... which is correct.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Actually getting 1 first then 0.

Edit. too slow :(
IgglePiggle
New User
New User
Posts: 6
Joined: Sun Jul 06, 2008 6:54 am
Location: Manchester, UK

Post by IgglePiggle »

Thanks for the feedback guys :)

is anyone who's getting 1 then 0 on Vista?
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Just changed to my vista computer and still getting 1 then 0. :?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> am I misunderstanding what values should be returned?

0 = Not visible and 1 = visible.

> presumably you mean you are getting 0 then 1 in the above test?

In Marco2007's example, yes. But 1 and 0 actually. :)

I'm going to ask for a third time to see some code from you that shows the
problem. We would've had your problem solved hours ago if you just did it.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> GetgadgetState(#Button) returns 0 each time no matter what the status is

GetGadgetState() isn't used to test if a gadget is visible. For a ButtonGadget,
it only shows if the button is toggled or not, depending if it was created with
the #PB_Button_Toggle flag.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Don't forget that IsWindowVisible will return 0 for the gadgets if the window
itself is hidden, even though the gadgets on it are not. I fell into this trap
once, and only just remembered it today in an app I'm writing.
Post Reply