Im using c++ Codegear 2009, and i have a form that should be displayed with ->ShowModal() method. When the user clicks outside this form, i need to capture the event. No idea about how to do it.... Thanks to all
Asked
Active
Viewed 400 times
0
-
[SetCapture](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646262.aspx). – IInspectable May 18 '15 at 14:34
-
@IInspectable wouldn't that prevent the user from interacting with any controls on the form? – andlabs May 18 '15 at 17:18
-
@andlabs: You are correct, capturing mouse input prevents that input from reaching another control, so this is not a viable solution. – IInspectable May 19 '15 at 09:18
-
what about checking the loss of focus (`OnExit` event ) or in some timer testing if focus is in any of your components if not then a click occurred. What you mean by click outside? (another window,desktop or booth? you can intercept messages by hooking to WindProc of window if you have access and handle to it ... – Spektre May 21 '15 at 07:10
-
thanks! the OnExit event does not trigger, because the windows is modal, so its impossible to loose focus. The option about intercept messages by hooking to WinProc sounds good... can u explain it to me? – Tirma May 21 '15 at 10:18
-
When you say "outside the form", do you mean "on my program's window (the one that is being blocked by the modal form)" or "outside my program at all" or both? – andlabs May 21 '15 at 21:28
-
@Tirma you can convert the form to normal form , with stay on top and on OnExit event do what you need and set Focus back to it. This way when you click outside you lose focus for a fragment of a second (still will see the focus color change flicker) but you will detect the click ... If you want to hook to WindProc you NEED TO USE WINAPI see this http://stackoverflow.com/a/7539034/2521214 – Spektre May 22 '15 at 07:25
-
Thanks @Spektre. I think it will works! – Tirma May 22 '15 at 09:35
-
@Tirma I use the first option all the time ... in BDS2006 projects – Spektre May 22 '15 at 09:57
-
You probably shouldn't hook into the Windows API for this. [`WM_ACTIVATE` is your friend.](http://blogs.msdn.com/b/oldnewthing/archive/2014/05/21/10527168.aspx) – andlabs May 23 '15 at 18:14