BindEvent()

Just starting out? Need help? Post your questions and find answers here.
lule
User
User
Posts: 31
Joined: Fri Sep 17, 2010 8:22 pm

BindEvent()

Post 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?
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.10 LTS (Linux - x64)
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: BindEvent()

Post 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
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: BindEvent()

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: BindEvent()

Post 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'.
BERESHEIT
lule
User
User
Posts: 31
Joined: Fri Sep 17, 2010 8:22 pm

Re: BindEvent()

Post 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?
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.10 LTS (Linux - x64)
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: BindEvent()

Post 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

:mrgreen:
lule
User
User
Posts: 31
Joined: Fri Sep 17, 2010 8:22 pm

Re: BindEvent()

Post by lule »

it's help, but it's not working!

after resizing the window, webgadget is not resizing.
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.10 LTS (Linux - x64)
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: BindEvent()

Post 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. :|
:mrgreen:
lule
User
User
Posts: 31
Joined: Fri Sep 17, 2010 8:22 pm

Re: BindEvent()

Post 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
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.10 LTS (Linux - x64)
lule
User
User
Posts: 31
Joined: Fri Sep 17, 2010 8:22 pm

Re: BindEvent()

Post 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
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.10 LTS (Linux - x64)
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: BindEvent()

Post 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

BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
lule
User
User
Posts: 31
Joined: Fri Sep 17, 2010 8:22 pm

Re: BindEvent()

Post by lule »

Thank you all for your support.
Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy.
PureBasic 6.10 LTS (Linux - x64)
Post Reply