Board index » delphi » Trapping clicks outside MODAL TForms

Trapping clicks outside MODAL TForms

I want to trap user mouse clicks outside modal TForms.

We all know users click anywhere and everywhere, even when programmers
think they are not supposed to do that.

So if we say MODAL, a user might decide he wants to "instantly escape"
from that and proceed elsewhere. The user clicks elsewhere. The user
has noticed the modal window, but does not want to proceed with it.

Let's trap that mouse click, close the form, treat it as "cancel" or
false" and let the user get on with what he wants to do. Instead
the user gets: BEEP.

A default value might be returned in many cases. Using MODAL seems to
make programming structures very easy to follow. That is so nice about
MODAL but that beeping is sad.

Regarding the "but-the-user-must-click-here" argument, if absolutely
necessary, one could still put a warning pop-up message in the event
handler.

This would all be easy if there was a TForm.OnClickOutside() or
TForm.OnDeactivateOutside() event. Possible? The modal TForm has the
focus at that point, hasn't it?

Do we need to rewrite the TForm component to trap this event?

Who knows an answer?

Emails appreciated. I will reply.

Matthew

 

Re:Trapping clicks outside MODAL TForms


Quote
Matthew wrote:

> I want to trap user mouse clicks outside modal TForms.

Simple: SetCapture. Now _all_ mouse messages in the entire system
comes to your form. Of course, you'll have to figure out if the
user simply wants to switch to another app. But there's where
WindowFromPoint comes in handy. If that app's hInstance is the
same as the global variable hInstance, you have an 'escape.' If
not, you have an attempt at switching apps. To get the instance
variable of another app, see GetWindowWord in D1 and GetWindowLong
in D2.

Hope this helps.

M.

--
Martin Larsson, author of several unknown utilities for DOS and Windows.
mailto:martin.lars...@delfi-data.msmail.telemax.no
http://www.delfidata.no/users/~martin
X.400:G=martin;S=larsson;O=delfi-data;P=msmail;A=telemax;C=no

Re:Trapping clicks outside MODAL TForms


Quote
Matthew wrote:

> I want to trap user mouse clicks outside modal TForms.

> We all know users click anywhere and everywhere, even when programmers
> think they are not supposed to do that.

> So if we say MODAL, a user might decide he wants to "instantly escape"
> from that and proceed elsewhere. The user clicks elsewhere. The user
> has noticed the modal window, but does not want to proceed with it.

> Let's trap that mouse click, close the form, treat it as "cancel" or
> false" and let the user get on with what he wants to do. Instead
> the user gets: BEEP.

> A default value might be returned in many cases. Using MODAL seems to
> make programming structures very easy to follow. That is so nice about
> MODAL but that beeping is sad.

> Regarding the "but-the-user-must-click-here" argument, if absolutely
> necessary, one could still put a warning pop-up message in the event
> handler.

> This would all be easy if there was a TForm.OnClickOutside() or
> TForm.OnDeactivateOutside() event. Possible? The modal TForm has the
> focus at that point, hasn't it?

> Do we need to rewrite the TForm component to trap this event?

> Who knows an answer?

> Emails appreciated. I will reply.

> Matthew

Do you really have to use a MODAL form? When we want a form to behave
like a modal form, but NOT BEING a MODAL form, we can take the
OnDeactivate event, show a warning/error message to user and, if is that
the case, give the control back to the form, LIKE a MODAL form!!!

Let me know if that works!

Silvio

Re:Trapping clicks outside MODAL TForms


Com...@lottery.powernet.co.uk (Matthew) seems to have typed:

Quote
>I want to trap user mouse clicks outside modal TForms.
>Let's trap that mouse click, close the form, treat it as "cancel" or
>false" and let the user get on with what he wants to do. Instead
>the user gets: BEEP.

I recently had to figure this out to make my own "fake-modal" form.

One easy way to do it (if your modal form is simple) is to hook
Application.OnMessage.  Don't make your form modal, just
show it, then set Application.OnMessage to a handler (say,
FakeModal) which checks whether Msg.message is between
WM_MOUSEFIRST and WM_MOUSELAST and if so, if
Msg.HWND equals your form or one of its children.  On a click
outside the window, you can then close the form, or decide
to handle the message, re-show the form, etc.

Another variant, which I haven't tried, would be to extract the
mouse x and y from mouse messages and check if they are in
the form.

This method has the virtue/limitation of only seeing events sent
to WinControls in your application.

Hope this helps.

Re:Trapping clicks outside MODAL TForms


Quote
esimp...@eramp.net (Evan Simpson) wrote:
>Com...@lottery.powernet.co.uk (Matthew) seems to have typed:
>>I want to trap user mouse clicks outside modal TForms.
>>Let's trap that mouse click, close the form, treat it as "cancel" or
>>false" and let the user get on with what he wants to do. Instead
>>the user gets: BEEP.

Perhaps you can use MouseCapture ??

Best regards
Frank
--
// Frank Mikalsen, System Developer, Finale a.s      
// Homepage: http://home.sol.no/frankm
// Author of ShareWare: Silent Partner Backup Screensaver v2.60
// Download: http://www.winsite.com/pc/win3/desktop/spbck260.zip

Other Threads