Mouse leave event... again (Windows specific)
Hi list,
(Longish post...)
A welcome addition to the output-pane input-model mechanism, in my opinion,
would be the ability to capture the 'mouse leave' event (there has been some
previous discussion of this). Up until recently I have been implementing this
via a timer, which is scheduled when the mouse enters the pane, checking
whether the mouse has left and unscheduling itself when it has.
This scheme has not proved altogether satisfactory, however, so I decided to
see if I couldn't somehow intercept the Windows WM_MOUSELEAVE message, which is
(as the name suggests) specifically designed for this purpose. This requires
accessing the output-pane's underlying window procedure, which can be done via
a well-established technique known as 'subclassing'. This is not subclassing in
the familiar OO sense, but a means by which a new, user-defined window
procedure can be substituted for the old one. All you need is the pane's
handle, and a few Windows constants and procedures, such as SetWindowLongPtr.
The address of the old procedure is retained so that it can be called to handle
any messages not intercepted by the new one (or the same ones, if required). So
I define a new window procedure as a lisp foreign-callable, and use it to
intercept WM_MOUSELEAVE. It's also necessary to call TrackMouseEvent for this
to work, which I do in my motion callback (once, on mouse entry).
This scheme *seems* to work OK. At least, I haven't experienced any noticeable
issues with it in the few weeks I have been using it. Subclassing can also be
used to implement 'owner drawn' controls, and in fact I have experimented
lightly with this, creating (Windows look&feel purists stop reading now!) a
menubar with a gradient background and a box highlight instead of the standard
filled rectangle. I don't use any internal CAPI functions for this, it's all
Windows FLI stuff (the handle of the 'top level' menu in an interface can be
retrieved via GetMenu). I don't have any plans to introduce this into my
application, but I wonder how far one could take it? Could this be dangerous in
any way, maybe conflicting with low-level CAPI stuff? As I say, subclassing in
this sense is a well-established technique. It's discussed at length on the
MSDN page on window procedures - in fact it forms the bulk of that article:
http://msdn.microsoft.com/en-us/library/ms633569(v=VS.85).aspx
I have code I would be more than willing to share, if anybody is interested.
Best wishes,
Chris