In a forum, the question was
Is there a way to automatically close a form once the cursor was moved off of it.
I don’t know why, but this was one of those forum questions that truly got me curious and so I needed to find a way to do this for my own personal knowledge.
I came up with an initial solution, but it wasn’t foolproof and wouldn’t necessarily work for all setups and so I slept on it and woke up with a fundamentally simple solution. I have to admit, the solution only came to me because of some recent work I had to do for a client which required me to override the system cursor (in an Outlook project) and so I had become aware of certain available cursor APIs. Armed with this basic knowledge, I figure there had to be a way to compare the cursor’s position against the form’s boundaries and so the solution was born! With 2 simple APIs and the form’s timer event, it became pretty straightforward to accomplish and can be ported to pretty much any setup.
The following demo has everything you need (both 32 and 64-bit API declarations) with a working example so you can dissect the concept to be in a position to integrate it into your own project.
Continue reading →