Page 1 of 1
BindEvent()
Posted: Tue Oct 21, 2014 7:46 am
by lule
I don't understand the bindevent command with all arguments.
BindEvent(Event, @Callback() [, Window [, Object [, EventType]]])
Is it possible to have samples with Object and EventType?
Re: BindEvent()
Posted: Tue Oct 21, 2014 8:19 am
by bbanelli
lule wrote:I don't understand the bindevent command with all arguments.
BindEvent(Event, @Callback() [, Window [, Object [, EventType]]])
Is it possible to have samples with Object and EventType?
Maybe you'll get it better through
PostEvent() parameters in these examples ->
http://www.purebasic.fr/english/viewtop ... 23&t=60552
Re: BindEvent()
Posted: Tue Oct 21, 2014 3:23 pm
by Demivec
lule wrote:I don't understand the bindevent command with all arguments.
BindEvent(Event, @Callback() [, Window [, Object [, EventType]]])
http://purebasic.com/documentation/wind ... event.html
The arguments for Window, Object and EventType limit the scope of the call to BindEvent().
You don't need them if you want one procedure to handle any possible event. On the other hand if you want a procedure to only handle a certain event type (see object type for those allowed) for certain objects (i.e a gadget, menu, or systray) on a certain window then you would use them.
Re: BindEvent()
Posted: Tue Oct 21, 2014 5:27 pm
by netmaestro
It's all self-explanatory exept Object. Object is a gadget#. In fact it would be more helpful to call it 'gadget' in the doc instead of 'object'.
Re: BindEvent()
Posted: Wed Oct 22, 2014 7:33 am
by lule
Thanks for your responses.
I understood Object/#Gadget or #Menu...
Have you a short sample with Object Or And EventType, who work fine?
Re: BindEvent()
Posted: Wed Oct 22, 2014 8:57 am
by es_91
I do not know if this helps you...
Code: Select all
Procedure WindowSizer ()
Shared Window, Web
ResizeGadget (Web, 20, 20, WindowWidth (Window) - 40, WindowHeight (Window) - 40)
EndProcedure
Window = OpenWindow (#PB_Any, 100, 100, 200, 200, "Resize it!", #PB_Window_SizeGadget| #PB_Window_SystemMenu)
Web = WebGadget (#PB_Any, 20, 20, WindowWidth (Window) - 40, WindowHeight (Window) - 40, "http://www.google.de/")
BindEvent (#PB_Event_SizeWindow, @ WindowSizer (), Window, Web, #PB_EventType_TitleChange)
Repeat
Select WaitWindowEvent ()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = Web And EventType() = #PB_EventType_TitleChange
SetWindowTitle (Window, "Window size = " + Str (WindowWidth (Window)) + "x" + Str (WindowHeight (Window)))
WindowSizer ()
EndIf
EndSelect
ForEver
Re: BindEvent()
Posted: Wed Oct 22, 2014 9:38 am
by lule
it's help, but it's not working!
after resizing the window, webgadget is not resizing.
Re: BindEvent()
Posted: Wed Oct 22, 2014 10:52 am
by es_91
You need to type something into Google's search text input and press enter to trigger the resize. Sorry, but i found no better way to demonstrate it. Maybe somebody else can set this right, my skills are incomplete here.

Re: BindEvent()
Posted: Wed Oct 22, 2014 12:58 pm
by lule
es_91,
if you test your code without bindevent, It's work too.
Code: Select all
Procedure WindowSizer ()
Debug "WindowSizer"
Debug EventGadget()
Shared Window, Web
ResizeGadget (Web, 20, 20, WindowWidth (Window) - 40, WindowHeight (Window) - 40)
EndProcedure
Window = OpenWindow (#PB_Any, 100, 100, 700, 200, "Resize it!", #PB_Window_SizeGadget| #PB_Window_SystemMenu)
Web = WebGadget (#PB_Any, 20, 20, WindowWidth (Window) - 40, WindowHeight (Window) - 40, "http://www.google.de/")
;BindEvent (#PB_Event_SizeWindow, @ WindowSizer (), Window, Web, #PB_EventType_TitleChange)
Repeat
Select WaitWindowEvent ()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = Web And EventType() = #PB_EventType_TitleChange
SetWindowTitle (Window, "Window size = " + Str (WindowWidth (Window)) + "x" + Str (WindowHeight (Window)))
WindowSizer ()
EndIf
EndSelect
ForEver
Re: BindEvent()
Posted: Wed Oct 22, 2014 6:40 pm
by lule
I post what i want to do
Code: Select all
Structure tagGADGETAMOI
hTypeID.i
hWindow.i
hGadget.i
EndStructure
Procedure __GadgetAMoi_Resize()
Protected *pGadget.tagGADGETAMOI
If IsGadget(EventGadget())
*pGadget.tagGADGETAMOI = GetGadgetData(EventGadget())
If *pGadget
ResizeGadget(*pGadget\hGadget, -1, -1, WindowWidth(*pGadget\hWindow) * 0.9, WindowHeight(*pGadget\hWindow) * 0.9)
EndIf
Else
EndIf
EndProcedure
Procedure GadgetAMoi(hID, x, y, Width, Height, Value.s)
Protected *pGadget.tagGADGETAMOI = AllocateMemory(SizeOf(tagGADGETAMOI))
If hID = #PB_Any
*pGadget\hGadget = StringGadget(#PB_Any, x, y, Width, Height, Value)
Else
StringGadget(hID, x, y, Width, Height, Value)
*pGadget\hGadget = hID
EndIf
SetGadgetData(*pGadget\hGadget, *pGadget)
*pGadget\hWindow = GetActiveWindow()
;Here the gadget will resize wen his window is resize
BindEvent(#PB_Event_SizeWindow, @__GadgetAMoi_Resize(), *pGadget\hWindow, *pGadget\hGadget)
EndProcedure
Global.i Lfenetre, Lgadget
Lfenetre = 322
Lgadget = Lfenetre-16
; Shows possible flags of StringGadget in action...
If OpenWindow(0, 0, 0, Lfenetre, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
StringGadget(1, 8, 10, Lgadget, 20, "Normal StringGadget...")
GadgetAMoi(2, 8, 35, Lgadget, 20, "1234567")
StringGadget(3, 8, 60, Lgadget, 20, "Read-only StringGadget", #PB_String_ReadOnly)
StringGadget(4, 8, 85, Lgadget, 20, "lowercase...", #PB_String_LowerCase)
StringGadget(5, 8, 110, Lgadget, 20, "uppercase...", #PB_String_UpperCase)
StringGadget(6, 8, 140, Lgadget, 20, "Borderless StringGadget", #PB_String_BorderLess)
StringGadget(7, 8, 170, Lgadget, 20, "Password", #PB_String_Password)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: BindEvent()
Posted: Wed Oct 22, 2014 10:04 pm
by BasicallyPure
hi lule,
The problem with your code is that you cannot use the 'object' option in BindEvent()
when the event is #PB_Event_SizeWindow.
The event is not coming from the string objects, it is coming from the window.
Try this code and see that if you include the 'object' parameter it will not work.
BP
Code: Select all
Procedure Callback()
Debug "resize event"
EndProcedure
OpenWindow(0,0,0,200,100,"",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
StringGadget(1,10,10,100,25,"ABC123XYZ")
;BindEvent(#PB_Event_SizeWindow,@Callback(),0,1) ; <-- does not work this way
BindEvent(#PB_Event_SizeWindow,@Callback(),0) ; <-- this works
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: BindEvent()
Posted: Thu Oct 23, 2014 12:52 pm
by lule
Thank you all for your support.