BBC BASIC for Windows
Programming >> Libraries >> New EVENTLIB library
http://bb4w.conforums.com/index.cgi?board=libraries&action=display&num=1331378257

New EVENTLIB library
Post by admin on Mar 10th, 2012, 10:17am

I have written a new BB4W library EVENTLIB:

http://tech.groups.yahoo.com/group/bb4w/files/Libraries/EVENTLIB.BBC

This library is intended to address the issues discussed in these recent threads:

http://tech.groups.yahoo.com/group/bb4w/message/16863
http://tech.groups.yahoo.com/group/bb4w/message/17189
http://tech.groups.yahoo.com/group/bb4w/message/17397
http://tech.groups.yahoo.com/group/bb4w/message/17573

The EVENTLIB library is extremely simple; it consists of only three procedures as follows:
If you need to be informed that the event queue overflowed, you can register a handler for that by specifying an event ID of zero:

Code:
      PROC_eventregister(0, PROCoverflow()) 

Despite the library's simplicity it is quite powerful, and goes a long way to solving the problem of distributing events to multiple handlers (potentially in multiple libraries). It is designed to use only a small amount of memory.

Here's a simple test program illustrating its use:

Code:
      WM_MOVE = 3
      WM_SIZE = 5
      WM_TIMER = 275
      WM_LBUTTONDOWN = 513
      WM_RBUTTONDOWN = 516
      
      INSTALL @lib$+"EVENTLIB"
      
      PROC_eventinit
      PROC_eventregister(WM_TIMER, PROCtimer())
      PROC_eventregister(WM_TIMER, PROCanothertimer())
      PROC_eventregister(WM_MOVE, PROCmove())
      PROC_eventregister(WM_SIZE, PROCsize())
      
      PROC_eventinit
      PROC_eventregister(WM_LBUTTONDOWN, PROCmouse())
      PROC_eventregister(WM_RBUTTONDOWN, PROCmouse())
      PROC_eventregister(0, PROCoverflow())
      
      REPEAT
        PROC_eventpoll
        WAIT 0
      UNTIL FALSE
      END
      
      DEF PROCtimer(M%, W%, L%)
      PRINT "Timer fired: "~ M% W% L%
      ENDPROC
      
      DEF PROCanothertimer(M%, W%, L%)
      PRINT "Timer fired (2) ";
      ENDPROC
      
      DEF PROCmove(M%, W%, L%)
      PRINT "Window moved: "~ M% W% L%
      ENDPROC
      
      DEF PROCsize(M%, W%, L%)
      PRINT "Window resized: "~ M% W% L%
      ENDPROC
      
      DEF PROCmouse(M%, W%, L%)
      PRINT "Mouse clicked: "~ M% W% L%
      ENDPROC
      
      DEF PROCoverflow(M%, W%, L%)
      PRINT "Event queue overflowed!!"
      ENDPROC 

Richard.
Re: New EVENTLIB library
Post by dsquare on Dec 10th, 2015, 7:10pm

I am new to BB4W and am using an old favourite of mine (LIFE) to learn programming in Windows. My original experience with this stuff was a LONG time ago.
The EVENTLIB example works just fine and would do what I need for selecting an area of my grid, IF, the LBUTTONUP worked as well as the LBUTTONDOWN. I have set WM_LBUTTONUP = 514 as I believe this is the right msg but I get no events when letting the left mouse button up. I assume there is more to this, but maybe this will not work for some other reason. I am running the example code to do this test.
Re: New EVENTLIB library
Post by Zaphod on Dec 11th, 2015, 12:21pm

The message code 514 is not passed onto the user so you cannot get this event notification that way.
However, the mouse up up may result in a WM_COMMAND event depending what you are over when you click.

If you need to know when the mouse key is released then you would use the mouse down event to start a polling loop of the mouse button via INKEY(-10) and see what the state of the button is. Or you could start polling MOUSE. The 513 interrupt lets you know the mouse position or you can get that from the MOUSE command. Don't forget to put a WAIT in the polling loop or you will use 100% of CPU time for one processor core.
Re: New EVENTLIB library
Post by dsquare on Dec 11th, 2015, 4:09pm

Thanks for the update. I suspected that. I saw some code that was doing what you suggested but wasn't sure I had to do it that way.
Dave
Re: New EVENTLIB library
Post by RNBW on Dec 12th, 2015, 11:37am

Quote:
I have written a new BB4W library EVENTLIB:

http://tech.groups.yahoo.com/group/bb4w/files/Libraries/EVENTLIB.BBC


All I get from the link is "Oops Invalid Path"

When I go into /bb4w/files/Libraries I can't find EVENTLIB.BBC
Re: New EVENTLIB library
Post by Zaphod on Dec 12th, 2015, 5:48pm

I believe that Eventlib was part of the distribution in Version 6. If you haven't upgraded then you may not have it otherwise it should already be in your Lib folder. Richard usually takes it down when it gets included in a distribution. However, some of the links in the wiki seem to be missing as well.
There are also some Event libraries by others in the Temp folder if you are just experimenting. The Event queue and event handling are similar to techniques Richard has used elsewhere.

Re: New EVENTLIB library
Post by RNBW on Dec 12th, 2015, 8:05pm

My mistake. I should have looked at the date of Richard's post. I thought it was an update to BB4W V6 EVENTLIB.BBC. But I see now that dsquare's post was in response to a much earlier posting.
All resolved!