Page 1 of 2

Using event handlers!

Posted: Mon Apr 03, 2006 12:03 am
by srod
THE LIBRARY IS NOW COMPLETE. SEE THE FOLLOWING THREAD FOR DETAILS.


http://www.purebasic.fr/english/viewtop ... 768#138768

Posted: Mon Apr 03, 2006 2:00 am
by GeoTrail
Sounds interesting. I'll give that a try when I get a chance tomorrow :)

Re: Using event handlers!

Posted: Mon Apr 03, 2006 10:08 am
by Kiffi
Hello srod,

looks very good! :D

Keep it up! Image

Greetings ... Kiffi

Posted: Mon Apr 03, 2006 3:13 pm
by ebs
srod,

Very good! :)

I added a few gadgets to your demo program and everything seems to work fine.
I'd be happy to help you with the testing and/or development, if you'd like.

One mistake I noticed in the User Guide:
In the description of the Event Handler functions, the second event constant
should be "#OnLostFocus", not "#OnLostEnter".

Regards,
Eric

Posted: Mon Apr 03, 2006 3:36 pm
by srod
Thanks for the replies. It's early days yet, but I think the 'foundations' have been laid.
One mistake I noticed in the User Guide:
In the description of the Event Handler functions, the second event constant
should be "#OnLostFocus", not "#OnLostEnter".
Doh! :D Thanks ebs, I'll tidy that up later tonight.

Posted: Tue Apr 04, 2006 12:15 am
by srod
Update:
Now covers 15 standard events including menu item / toolbar button selections; painting, sizing, moving, maximizing windows, gadget activation / deactivation plus the more familar mouse / cursor events etc.

Will add a few more what I would call 'generic' events and then will move on to specific types of gadgets and their underlying windows messages etc.

Again, thanks to any able to help out with the testing. :D

See the first post for the download link.

Posted: Tue Apr 04, 2006 2:26 am
by ebs
srod,

I just tried out your new version and I'm liking it more and more! There isn't that much I really like about Visual Basic, but its "event model" can be pretty handy.

I noticed a convenient thing when using the "#OnButtonClick" event handler: the "wParam" field in the sender structure holds the PB gadget number.
This makes it easy to associate multiple controls (like option buttons) to one event handler, then determine which control was clicked by examining wParam.
This is similar to Visual Basic's control arrays. Do you know if this is true for other event types?

Regards,
Eric

Posted: Tue Apr 04, 2006 7:18 am
by srod
ebs wrote:I noticed a convenient thing when using the "#OnButtonClick" event handler: the "wParam" field in the sender structure holds the PB gadget number.
This makes it easy to associate multiple controls (like option buttons) to one event handler, then determine which control was clicked by examining wParam.
This is similar to Visual Basic's control arrays. Do you know if this is true for other event types?
Yes, forgot to document that! Sorry. I'll write a better user guide tonight, it's a bit of a mess at the moment.

The same is true for the "#OnMenuItemSelect" event which works for menus and toolbar buttons in exactly the same way that the regular Purebasic message system operates.

Thanks for testing.

Posted: Tue Apr 04, 2006 11:12 pm
by srod
Removed.

Posted: Tue Apr 04, 2006 11:29 pm
by Kiffi
Whow! I love your code! :D

Here is another simple example for your demo2.pb:

Code: Select all

;The following event procedure allows only numbers.
Procedure.l KeyPress(*sender.PB_Sender)
  Protected result
  If FindString("1234567890"+Chr(8), Chr(*sender\wParam), 1)
    result = #PB_ProcessPureBasicEvents
  Else
    result = 0 ;This ensures the character is ignored.
  EndIf
  ProcedureReturn result
EndProcedure
Thanks again & Greetings ... Kiffi

Posted: Wed Apr 05, 2006 12:00 am
by srod
Glad you like it.

Nice example, although Purebasic allows numeric only string gadgets through the #PB_String_Numeric flag.

Wait, I've just noticed the #PB_String_UpperCase flag!!! Doh! :D Was that added for PB 4? I haven't noticed that one before!

Oh well, the principle remains though in that the #OnKeyPress event allows for a heck of a lot of possible customising.

Thanks.

Posted: Wed Apr 05, 2006 12:11 am
by GeoTrail
Looks very cool :)

Posted: Wed Apr 05, 2006 11:20 pm
by srod
Update:

Bugs fixed, more events added (coloured blue below). Also more demo progs including drag and drop to a list icon.

The full list of currently supported events runs as follows:
  • #OnButtonClick
  • #OnChange
  • #OnClose
  • #OnContextMenuPopup
  • #OnCursorEnter
  • #OnCursorExit
  • #OnDragDrop
  • #OnDblClick
  • #OnGotFocus
  • #OnKeyDown
  • #OnKeyPress
  • #OnKeyUp
  • #OnLostFocus
  • #OnMaximize
  • #OnMenuItemSelect
  • #OnMinimize
  • #OnMouseDown
  • #OnMouseOver
  • #OnMouseUp
  • #OnMove
  • #OnPaint
  • #OnResize
Will look at various forms of 'item selection' in particular gadgets next.

See post 1 for download link.

Posted: Wed Apr 05, 2006 11:30 pm
by techjunkie
Great work! :D

Posted: Wed Apr 05, 2006 11:41 pm
by GeoTrail
This is very impressive. Would be cool to have this as a part of the PB core ;)