Page 1 of 1

Is gadget hidden or not?

Posted: Sun Jul 06, 2008 7:02 am
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!

Re: Is gadget hidden or not?

Posted: Sun Jul 06, 2008 7:07 am
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.

Posted: Sun Jul 06, 2008 7:42 am
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

Posted: Sun Jul 06, 2008 7:48 am
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

Posted: Sun Jul 06, 2008 8:01 am
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)))

Posted: Sun Jul 06, 2008 8:08 am
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?

Posted: Sun Jul 06, 2008 9:33 am
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?

Posted: Sun Jul 06, 2008 9:39 am
by eesau
Here's the debug output:

Code: Select all

BEFORE: 1
AFTER: 0
... which is correct.

Posted: Sun Jul 06, 2008 9:39 am
by Derek
Actually getting 1 first then 0.

Edit. too slow :(

Posted: Sun Jul 06, 2008 9:44 am
by IgglePiggle
Thanks for the feedback guys :)

is anyone who's getting 1 then 0 on Vista?

Posted: Sun Jul 06, 2008 9:59 am
by Derek
Just changed to my vista computer and still getting 1 then 0. :?

Posted: Sun Jul 06, 2008 12:09 pm
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.

Posted: Sun Jul 06, 2008 12:13 pm
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.

Posted: Tue Jul 15, 2008 2:01 pm
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.