BLESS (BLitz EventS System) beta released!

Community Forums/Showcase/BLESS (BLitz EventS System) beta released!

soja(Posted 2004) [#1]
Well, almost coincidentally on my 1000th post in the Blitz forums, I'm announcing that I've finally released something. =) (Thanks to those who encouraged me.) I hope you find it useful.

Here's the README... Post any questions, successes, failures, etc on the board.

Get it from http://www.mintysoftware.com

...

BLESS (BLitz EventS System)
Take control of Windows events!

--------------
What is BLESS?
--------------

BLESS stands for "BLitz EventS System". It is a small DLL made to augment the event-handling power of BlitzPlus and Blitz3D, hopefully alleviating some of their shortcomings.

-----------------------
Why would I want BLESS?
-----------------------

BlitzPlus users, have you ever wished BlitzPlus had a certain feature, and been frustrated to find that you couldn't code it yourself because of the shortcomings of the language? Blitz3D users, have you ever wanted some of the event-handling power of BlitzPlus?

BLESS increases the number of Windows events your program can monitor and react to. BlitzPlus gives you access to 21 (or so) events. Blitz3D mostly just gives you access to input-related events. But, with BLESS, you can monitor and react to pretty much any Windows event that occurs for any window -- not just your own Blitz window.

Also, BLESS is built to be very open-ended. With a little knowledge of the Windows API and some documentation from MSDN, it can be a very powerful tool. It was written to be as unintrusive as possible, doing only what Blitz CAN'T do, thereby letting you, the Blitz programmer, implement whatever you like, however you like.

-------------------------
What can I do with BLESS?
-------------------------

Here are some of the things BLESS allows you to do, as shown in the example programs:
1) Create your own custom Windows gadgets by catching WM_PAINT and WM_DRAWITEM messages
2) Catch mouse events from any gadget
3) Monitor keypresses in another program, like notepad
4) Minimize your app to the system tray
5) Monitor system tray events, like clicks and mousemoves
6) Know when other windows are closed
7) Know when CUT, COPY, and PASTE are used
8) Know when a treeview node is expanded or contracted
9) Know when any item in any gadget (treeview, listbox, etc) is changed... with the mouse OR keyboard
10) Drag-and-Drop files into your window

But since there are so many different Windows messages, notifications, and events, there are many more possibilities with BLESS.

--------------------
How does BLESS work?
--------------------

You tell BLESS an event and gadgets/window you're interested in, and when BLESS notices the particular event happening to the particular gadget or window, it lets you know by sending a BLESS event to your Blitz program. What is a BLESS event? For BlitzPlus, the BLESS event is disguised as a special character code from the unused portion of the UTF-16 (unicode) range. For Blitz3D, it is disguised as a scancode for a non-existent keyboard key. Either way, for you to detect the event, it's as simple as using KeyHit (Blitz3D) or event $103 (Keystroke in BlitzPlus).

-------------------
How do I use BLESS?
-------------------

See "Bless Docs.txt" for more info. To quickly get up and running, it's as simple as this:

1) Put bless.bb and bless.dll in your development folder
2) Put bless.decls in your userlib folder
3) In your sourcecode, use:
Include "bless.bb"
4) If you're using Blitz3D, use this line:
Bless_UseAlternateMethod(True) ; Alternate BLESS event notification method
5) Then let BLESS know which event and window you want to monitor with Bless_RegisterEvent()
6) In your main loop or event loop, check BLESS events with KeyHit or event $103
7) Use EventData() to get any extended event information, if necessary
8) Before terminating your program, call:
Bless_UnregisterEvent(0)

That's it. Also, check out the examples' source code.

--------------------------------
Are there known issues in BLESS?
--------------------------------

Yes, BLESS is currently classified as beta. Here are some issues:

* Some problems may occur when running more than one program that uses BLESS (at the same time)
* In the Notepad Demo, sometimes Blitz3D doesn't process the WM_DESTROY message after rapidly pressing a bunch of characters and quickly closing Notepad
* If Bless_UnregisterEvent(0) isn't called before program termination, Windows may not completely unload the DLL for a few minutes, during which time BLESS events may not work completely.
* Since Bless_EventData only returns information for the last event that occurred of a certain BLESS event ID, any previous event data not queried will be lost. So, if events occur very rapidly, (like WM_MOUSEMOVE while rapidly moving the mouse), not all mouse event coordinates may be able to be retrieved.

-------------------------------------
Is there unknown territory for BLESS?
-------------------------------------

Yes, I'm interested in knowing how the following work:

1) Detecting some events (like WM_COMMAND and WM_NOTIFY) on Win95/98/ME systems
2) BLESS on Unicode-enabled systems (using the default BLESS event method)
3) BLESS on slow systems
4) BLESS on weirdo keyboards and other input devices (using the alternate BLESS event method)


RepeatUntil(Posted 2004) [#2]
God BLESS you, soja ;-)

THANK YOU VERY MUCH!! I tried BLESS and it works perfectly!! That's great!!!!!!!!!!!! Very very good job!!

I am interested by the drag'n'drop feature. I have implemented in Cod2Doc, and it works perfectly!! Thanks to you, Cod2Doc has now a full-featured drag'n'drop... And it will be useful to a lot of other applications also...

Also, I tried the demo you gave. All works perfectly, except the notepad demo. Notepad is opening, but then nothing more: no message, nothing when I type. I have Blitz 3D and win98...

By the way, can I already use BLESS in Cod2Doc? (next version is going to be released in a few days). Will it be free?

Thanks for this very good job!!


skn3(Posted 2004) [#3]
Very interesting. I don't much like the idea of using input events to hack into blitz, but it seems like a clever way to do it all :)


jfk EO-11110(Posted 2004) [#4]
Wow Soja, I was waiting for this since years. Thank you very much!


RepeatUntil(Posted 2004) [#5]
soja: when I use 2 instances of Cod2Doc with BLESS, then there is an error (in kernel32). Then windows is VERY slow, and almost frozen. I have to restart my computer (win98).
So it's like we can't run 2 programs with BLESS at the same time.
Is it a known bug of the beta version? Is there any chance it will be corrected in the future version?
Thanks!


aCiD2(Posted 2004) [#6]

--------------------------------
Are there known issues in BLESS?
--------------------------------

Yes, BLESS is currently classified as beta. Here are some issues:

* Some problems may occur when running more than one program that uses BLESS (at the same time)



RepeatUntil: Think that might have something to do with it? ^_^


BlitzSupport(Posted 2004) [#7]
Nice work, Soja. One little error is that the default example has 2 references to Shell_NotifyIcon instead of Bless_NotifyIcon so fails unless people have defined Shell_NotifyIcon already. Very impressive though!


soja(Posted 2004) [#8]
RepeatUntil: All works perfectly, except the notepad demo. Notepad is opening, but then nothing more: no message, nothing when I type. I have Blitz 3D and win98...


Hmm, I was afraid of that. As I understand it, some (not all) of the messages are interpreted differently on 95/98/ME than on NT/2K/XP. This was one of the "unknown territories" for me.

RepeatUntil: By the way, can I already use BLESS in Cod2Doc? (next version is going to be released in a few days). Will it be free?

If you have confidence in it, you're welcome to use it as it is... It's certainly free right now, as it's a beta. I'm not sure if people will find it useful enough to charge for in the future, when all the issues have been worked out.

skn3[ac]: I don't much like the idea of using input events to hack into blitz, but it seems like a clever way to do it all

Yes, you're right, I would classify it as a "hack" too. =) As it stands, it seems to me the safest (and easiest) way to do it. Coding some other method of communication between bless.dll and your Blitz program would (a) be more complicated for the programmer, (b) have essentially introduced another message queue to the Blitz program, opening the door to all kinds of race conditions and such -- very, very difficult to deal with correctly, especially not having access to the internal workings of Blitz.

Fortunately, the "hack" is (hopefully) quite benign. It works ("plays nice") with Blitz' own internal message pump to get messages to the programmer via either unused UTF-16 codes or unused keyboard scancodes. I still wonder how it will work on a unicode-enabled machine (with the default method) or on a machine with some weird keyboard that actually uses the "unused" scancodes (with the alternate method).

Anyway, you should give it a try for your custom GDI stuff -- I wrote it partly with that dilemma in mind, having run into that problem before (no way to get WM_PAINT).

RepeatUntil: So it's like we can't run 2 programs with BLESS at the same time.
Is it a known bug of the beta version? Is there any chance it will be corrected in the future version?

Yes, as aCID2 noted, it's a known issue, though it seems to react much worse on a Win98 machine than on an XP machine. Yikes. I am planning on fixing that.

All, thanks for the kind words and support. I hope it (eventually?) works out great in your projects.


soja(Posted 2004) [#9]
Skidracer: ...references to Shell_NotifyIcon instead of Bless_NotifyIcon...

Good eye, James, thanks for the heads up and encouragement. I did indeed want it to work out of the gate for everybody -- looks like I missed that one.


RepeatUntil(Posted 2004) [#10]
By the way, the bug regarding 2 instances of BLESS is a difficult bug to correct?? Do you have any time scale to know when this bug will be corrected??
Thanks!


electronin(Posted 2004) [#11]
VERY cool, soja! downloading it now :)


soja(Posted 2004) [#12]
Do you have any time scale to know when this bug will be corrected?
Working on it now... I couldn't give the time scale for certain.


RepeatUntil(Posted 2004) [#13]
Just to put the pressure on you (he, he, he): Cod2Doc is waiting for your fix to be released :-)


VIP3R(Posted 2004) [#14]
BLESS has doubled the functionality of our latest BlitzPlus application.

Great work soja :)


RepeatUntil(Posted 2004) [#15]
Soja: were you able to fix BLESS?? If not, do you think it's possible to know when a second instance of BLESS is running and then disable it??


Bremer(Posted 2004) [#16]
Put this inside the kernel32.decls:

CreateMutex%(lpMutexAttributes%,bInitialOwner%,lpName$):"CreateMutexA" 


and then use this to detect if the program is running already, and if so then shut it down.

	Const ERROR_ALREADY_EXISTS=183
	CreateMutex(0,1,"My Program Instance") ; Mutex accessible to any program
	If GetLastError() = ERROR_ALREADY_EXISTS Then
		End
	EndIf


I don't remember who posted the above a while ago, but it will prevent a blitz program from starting more than once. Don't know if its of any help though.


soja(Posted 2004) [#17]
RepeatUntil: were you able to fix BLESS??

Not yet, but I'm in the middle of it. I can't say Windows makes it very easy -- you have to jump through a ton of hoops and stuff... I hope to have something up within a week or two (earlier if I get more time).

zawran: I don't remember who posted the above a while ago...

Coincidentally, me.
=)


Bremer(Posted 2004) [#18]
soja: I figured as much, but wasn't sure. You have been quite generous with your knowledge about the windowsApi and its use and you should know that its highly appreciated.


soja(Posted 2004) [#19]
You have been quite generous with your knowledge about the windowsApi and its use and you should know that its highly appreciated.

Thanks, it's my pleasure. I'm glad I could be helpful to you.


RepeatUntil(Posted 2004) [#20]
I would like to release Cod2Doc in a few days now. Soja, apparently this fix seems to be hard to implement (undoubtely because of windows :-( ). So I think I will use the solution that Zawran gave me: when a first instance of Cod2Doc is running, then I don't start Bless in the second instance of Cod2Doc.
This won't allow the Drag'n'Drop in the second instance of Cod2Doc, but it should work...

Anyway, let me know when the next version of Bless will be released. And THANK YOU for this excellent Bless!!!!!


soja(Posted 2004) [#21]
Yes, I've hit some snags (that and went away to Virginia for two weeks). Yes, it is because of WIndows. =) It's nothing that I can't handle, I think, but it is new territory, so of course, I don't expect you to wait for me. (Every time I think I'm getting somewhere, something new pops up in my way. Grr..)

Also, if you want to make sure you're updated, you can go to www.mintysoftware.com and sign up for the announcement list.

In the meantime, there is a workaround:
Check the return value of Bless_RegisterEvent. If it fails, try using another BLESS event (i.e. BLESS+5). You could, I suppose, just keep trying until you find one that works (up to BLESS+2047). Also, in the next release, I will change the error codes so that different return codes mean different errors. For example, 0 = BLESS event already in use, -1 = something else, etc.

Thanks for your support.


RepeatUntil(Posted 2004) [#22]
Hi Soja,

I have signed up to your list, to be sure to be updated at the right time.

I will try your workaround, and post here if I have some other questions!

Many thanks!