Hide Gadgets (Now with two examples)

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Hide Gadgets (Now with two examples)

Post by BackupUser »

Code updated for 5.20+ (same as HideGadget())

Restored from previous forum. Originally posted by wayne1.

Code: Select all

;hide gadget example #1

If OpenWindow(0, 100, 100, 395, 260, "Hide Gadgets Example", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget|#PB_Window_SizeGadget)
  
  ButtonGadget(0, 85, 90, 95, 30, "Hide Gadgets")
  ButtonGadget(1, 185, 90, 95, 30, "Does Nothing")
  ButtonGadget(3, 60, 0, 260, 30, "Restore Hidden Child Windows")
  StringGadget(2, 130, 150, 90, 30, "")
  CheckBoxGadget(4, 130, 50, 90, 30, "CheckBox")
  
  DisableGadget(3,1)

  Repeat
    EventID = WaitWindowEvent()

    If EventID = #PB_Event_CloseWindow
      Quit = 1
    EndIf
    
    If EventID = #PB_Event_Gadget

      Select EventGadget()
          
        Case 0

          pRect.RECT ; struct for GetClientRect()
          *Memory = AllocateMemory(300)
          h=GetWindow_(WindowID(0), #GW_CHILD);get first child window handle
          Repeat ;loop thru children
            GetWindowText_(h, *Memory, 50)
            If PeekS(*Memory)= "Restore Hidden Child Windows";don't ask to hide it
              Goto SkipIt
            EndIf
            
            If PeekS(*Memory) <> "" ;if it has text get it
              a = MessageRequester("Message", "This Gadgets text is "+PeekS(*Memory)+",Hide It??",#PB_MessageRequester_YesNo)
            Else ;if no text get approx. size
              GetClientRect_(h, pRect ); get size
              top$= Str(pRect\top) ;always 0
              bottom$=Str(pRect\bottom);height
              left$=Str(pRect\left);always 0
              right$=Str(pRect\right);width
              cr$=Chr(10)
              a=MessageRequester("Message", "This Gadget has no text but the size is approximately "+cr$+"Width " +right$+cr$+ "Height "+bottom$+cr$+" Hide It??",#PB_MessageRequester_YesNo)
            EndIf
            
            If a = 6
              ShowWindow_(h,#SW_HIDE);if yes hide child
              DisableGadget(3,0);enable restore button
            EndIf

            SkipIt:
            h=GetWindow_(h,#GW_HWNDNEXT); get next child
          Until h = 0

        Case 3
          DisableGadget(3,1);disable restore button just because we can
          d=GetWindow_(WindowID(0), #GW_CHILD);get first child
          
          Repeat ;loop thru  children
            ShowWindow_(d,#SW_SHOW);restore children
            d=GetWindow_(d,#GW_HWNDNEXT);get next child
          Until d = 0

      EndSelect

    EndIf
  Until Quit = 1

EndIf

End

Edited by - wayne1 on 09 October 2001 03:48:38
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by wayne1.

Code: Select all

; Hide gadget example #2

p1$="Will hide whatever gadget lies at specified region"
p2$="i.e. entering x80 y20 will hide button ''x=70 y=0''"
If OpenWindow(0, 100, 100, 395, 260, "Hide Gadgets Example #2", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |#PB_Window_SizeGadget)
  
  ButtonGadget(0, 70, 0, 100, 30, "x=70 y=0")
  ButtonGadget(1, 70, 80, 100, 30, "x=70 y=80")
  ButtonGadget(2, 220, 0, 100, 30, "x=220 y=0")
  ButtonGadget(3, 220, 80, 100, 30, "x=220 y=80")
  StringGadget(4, 180, 130, 55, 25, "80")
  StringGadget(5, 180, 170, 55, 25, "20")
  TextGadget(6, 120, 135, 55, 25, "Enter x pos")
  TextGadget(7, 120, 175, 55, 25, "Enter y pos")
  ButtonGadget(8, 80, 200, 100, 30, "Hide Gadget")
  ButtonGadget(9, 190, 200, 100, 30, "Restore Gadgets")
  TextGadget(10, 80, 40, 325, 25, p1$+Chr(10)+p2$)
  DisableGadget(9,1)
  Repeat
    EventID.l = WaitWindowEvent()
    
    If EventID = #PB_Event_CloseWindow
      Quit = 1
    EndIf
    If EventID = #PB_Event_Gadget
      
      Select EventGadget()
        Case 8
          
          p.POINT
          p\x=Val(GetGadgetText(4));set to user input
          p\y= Val(GetGadgetText(5));set to user input
          h = RealChildWindowFromPoint_(WindowID(0), (p\y << 16) | p\x );get handle of specified region
          If h =0
            MessageRequester("Message", "There is no child window or parent window at that position", 0)
          Else
            
            *Memory = AllocateMemory(300);buffer for GetWindowText()
            GetWindowText_(h, *Memory, 50);
            If PeekS(*Memory) = "Hide Gadgets Example #2"
              MessageRequester("Message", "You have selected the parent window region, hide aborted", 0);dont hide this!!
            Else
              If PeekS(*Memory) = "Restore Gadgets"
                MessageRequester("Message", "You have selected the ''Restore Gadgets'' button, hide aborted", 0);dont hide this either!!
              Else
                DisableGadget(9, 0)
                ShowWindow_(h, #SW_HIDE)
                MessageRequester("Message","OK, Hidden!"+Chr(10)+"Enter new coordinates and hide another Gadget.", Flags)
              EndIf
            EndIf
          EndIf
        Case 9
          DisableGadget(9,1);disable restore button just because we can
          d=GetWindow_(WindowID(0), #GW_CHILD);get first child
          Repeat ;loop thru children
            ShowWindow_(d, #SW_SHOW);restore children
            d=GetWindow_(d, #GW_HWNDNEXT);get next child
          Until d = 0
          
      EndSelect
      
    EndIf
  Until Quit = 1
  
EndIf

End
Post Reply