Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can a mouse click be detected outside of a modal form
Message
 
To
26/10/2006 13:10:30
Mike Sue-Ping
Cambridge, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01164759
Message ID:
01167138
Views:
21
This message has been marked as the solution to the initial question of the thread.
>I have a modal form that I show when a button is selected on another form. Is there any way to determine when a user has clicked on the underlying form (the one that contains the button that launched the modal form)?
>
>TIA
>Mike

Mike,

I got some time to think about the solution for modal form and here is something for you to consider (if you are still interested in keeping the form modal).

The goal is to release the modal form when user clicks somewhere outside this modal form. Modal form does not allow activating other form inside VFP screen.

In any case first you need to monitor the mouse position and check whether the mouse cursor is inside the modal form.

Now, if the cursor is outside the form, then you may check whether mouse is in the DOWN state, or you may check whether any other application window (which is outside VFP screen) is active.

If the user click inside the VFP screen, then MDOWN() can give you the answer. So, inside VFP screen it looks like a promising approach.
However outside the VFP screen MDOWN() does not work and you need to check globally for the active window.

So, here is what you can do:
1. add the timer to the modal form
2. Add to the form.init WinAPI declarations :
Declare short GetCursorPos In win32api String @ lpPoint
DECLARE SHORT GetWindowRect IN user32 INTEGER hwnd, STRING @lpRect
DECLARE INTEGER GetActiveWindow IN WIN32API
3. Add the new method to the form to deal with outputs of the functions above, like:
*form.dword2num:
PARAMETERS lcBuffer

RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
	BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
4. Add the following code to the Timer.Timer event:
* Timer.Timer
lpPoint = Space(8)
If GetCursorPos(@lpPoint)#0
	mouseX = thisform.dword2num(SUBSTR(lpPoint, 1,4))
	mouseY = thisform.dword2num(SUBSTR(lpPoint, 5,4))
Endif
	
cRect = Repli(Chr(0), 16)
= GetWindowRect(thisform.hwnd, @cRect)
WITH thisform
	FormLeft	= .dword2num(SUBSTR(cRect, 1,4))
	FormTop		= .dword2num(SUBSTR(cRect, 5,4))
	FormRight	= .dword2num(SUBSTR(cRect, 9,4))
	FormBottom	= .dword2num(SUBSTR(cRect, 13,4))
ENDWITH

cRect = Repli(Chr(0), 16)
= GetWindowRect(_VFP.hwnd, @cRect)
WITH thisform
	VFPLeft		= .dword2num(SUBSTR(cRect, 1,4))
	VFPTop		= .dword2num(SUBSTR(cRect, 5,4))
	VFPRight	= .dword2num(SUBSTR(cRect, 9,4))
	VFPBottom	= .dword2num(SUBSTR(cRect, 13,4))
ENDWITH

llMouseDown_OutofVFPScreen=NOT (between(mouseX, VFPLeft, VFPRight) AND;
  between(mouseY, VFPTop, VFPBottom)) ;
  AND NOT INLIST(GetActiveWindow(), _VFP.HWND, _screen.Hwnd, thisform.HWnd)
			
llMouseDown_In_VFPScreen_but_OutofForm = MDOWN() AND NOT (;
   between(mouseX, FormLeft, FormRight) AND;
   between(mouseY, FormTop, FormBottom)  )

IF llMouseDown_OutofVFPScreen OR llMouseDown_In_VFPScreen_but_OutofForm
	thisform.release
endif
GOod Luck
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform