Using event handlers!

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Using event handlers!

Post by srod »

THE LIBRARY IS NOW COMPLETE. SEE THE FOLLOWING THREAD FOR DETAILS.


http://www.purebasic.fr/english/viewtop ... 768#138768
Last edited by srod on Tue Apr 11, 2006 5:09 pm, edited 3 times in total.
I may look like a mule, but I'm not a complete ass.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Sounds interesting. I'll give that a try when I get a chance tomorrow :)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Using event handlers!

Post by Kiffi »

Hello srod,

looks very good! :D

Keep it up! Image

Greetings ... Kiffi
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Removed.
Last edited by srod on Wed Apr 05, 2006 11:14 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Looks very cool :)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Great work! :D
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

This is very impressive. Would be cool to have this as a part of the PB core ;)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply