The Esstu Pack

Index

S2Util and VX-REXX

The S2Utilities library has several functions designed specifically for Presentation Manager (especially VX-REXX) programs. VX-REXX allows a surprising amount of low-level functionality, such as the discovery of the HWND (WiNDow Handle, a unique number identifying one object among the (potentially) millions in the system) for any object, VX-REXX or otherwise; the trapping of any PM message and the viewing of the two MPARAMs; the sending of PM messages to any object in the system; and even the control (to a certain extent) of objects outside your program.

However one piece of information is lacking. There is no way, inside VX-REXX, to discover the Anchor Block Handle (HAB) for the currently executing program. Enter, therefore, S2Util, founded on a chance discovery while reading C header files for pleasure! OS/2 provides a routine for obtaining the HAB associated with a HWND. This opens up some interesting possibilities, including one causing me specific pleasure: a clipboard viewer. If this interests you also, read on. If not, read on anyway - you will probably find something which will grab you, jump out and hit you in the eye, or maybe even bore you to death. Enter at your own risk!

Caution: HWNDs as known to OS/2 are simple numbers, whereas HWNDs in VX-REXX have a prefix of '?HWND'. Also, VX-REXX stores HWNDs in hexadecimal, but S2GetHAB and S2MakeClipboardViewer require decimal input. Therefore, to get the HAB associated with some object, use the following code:

HWND=X2D(SUBSTR(VRGET("some_object_name","HWND"),6))
HAB=S2GETHAB(HWND)
To make the object into a clipboard viewer, you must not only get the HWND and pass it to MakeClipboardViewer, but also cause VX-REXX to respond to the messages sent by OS/2:
HWND=X2D(SUBSTR(VRGET("DT_CLIP","HWND"),6))
CALL S2MAKECLIPBRDVIEWER HWND
CALL VRMETHOD "DT_CLIP","DEFINEEVENT","WM_DRAWCLIPBOARD","0x67"
CALL VRSET "DT_CLIP","WM_DRAWCLIPBOARD","CALL DT_CLIP_CLIPCHANGE"
Of course, DT_CLIP can be replaced with any object name or handle - VRWINDOW() is a good choice, if you aren't doing anything visible with the information.

In the routine DT_CLIP_CLIPCHANGE(), which is called when the clipboard is changed (even if changed to precisely what it was - if you press Ctrl-Ins twice, two messages will be sent), use the ordinary GetClipboard method of the Application object to access the new contents of the clipboard.

CALL VRSET VRINFO("O"),"CAPTION",VRMETHOD("APPLICATION","GETCLIPBOARD")
This code sets the Caption (the displayed text) of the DescriptiveText object to be the new contents of the clipboard, making it a real clipboard viewer. There's just one limitation - it's text only. WM_DRAWCLIPBOARD messages will be sent when graphic data is cut/copied to the clipboard, but the GetClipboard method won't show it.

I do hope these snippets of information are helpful. If so, then my job is well worth while. Thankyou. (This quote is from Wallace Greenslade, on The Goon Show. I do hope these snippets... Oh? You've heard that already? Very well, I won't say it again. :-)