Stringgadget with a button?

Just starting out? Need help? Post your questions and find answers here.
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Stringgadget with a button?

Post by Poshu »

I've tried to add a button in a string gadget to obtain something like that:

Image
Image

But the last few tries didn't goes well. Any help?
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: Stringgadget with a button?

Post by PureLust »

If you like it simple, SetParent_() is your friend. :D

Code: Select all

OpenWindow(0,1,1,310,90,"Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0,5,50,300,24,"Test")
ButtonGadget(1,276,0,20,20,">")

SetParent_(GadgetID(1), GadgetID(0))   ; <===== simple, but with redrawing problems

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
To get even a perfect redrawing, the bit more complex way (edel (aka hallodri) showed me some day) will be the best:

Code: Select all

hWnd = OpenWindow(0,#PB_Ignore,#PB_Ignore,250,50,"leer",#WS_OVERLAPPEDWINDOW)

StringGadget(0,10,10,200,22,"",#WS_CLIPSIBLINGS)
ButtonGadget(1,210-22,12,20,19,"...")

SetWindowPos_(GadgetID(0),#HWND_BOTTOM,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)


Repeat
   event = WaitWindowEvent()

Until event = #PB_Event_CloseWindow
Last edited by PureLust on Fri Nov 12, 2010 2:23 am, edited 5 times in total.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Re: Stringgadget with a button?

Post by Poshu »

Damn. That was really easy. Thx a lot.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Stringgadget with a button?

Post by Rook Zimbabwe »

You could do it the old fashined way:

Code: Select all


Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Text_0
  #Button_0
  #String_0
EndEnumeration

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()
;-
Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
  Goober$ = GetGadgetText(#String_0)
  SetGadgetText(#Text_0, Goober$)
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, 112, "Window 0",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    ;If CreateGadgetList(WindowID(#Window_0))
      StringGadget(#String_0, 10, 15, 340, 30, "")
      ButtonGadget(#Button_0, 350, 15, 35, 30, ">>")
      RegisterGadgetEvent(#Button_0, @Button_0_Event())
      TextGadget(#Text_0, 10, 60, 375, 30, "", #PB_Text_Center | #PB_Text_Border)
      
   ; EndIf
  EndIf
EndProcedure

Open_Window_0()

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
:mrgreen:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply