Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to detect a key-stroke inside or outside VFP-application

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!

I do have a modal form.
I need to detect if one has clicked outside that form, may also be outside main vfp-window.
I do think there is an API for that but don't know about it.

Any suggestion?
-Bart
 
Can you explain why you would require this? The problem with detecting a mouse click with an API is you need to create a "wait state" which tends to chew up the CPU a bit. Take a look at faq184-5407

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,
I'm trying to create a toolbar like in Office with that little button with arrow beside the toobar-button.
I now instanciate a form to let the user make a choice but,
once clicked somewhere execpt on that (modal) form the modal form should be hided or released.
-Bart
 
Bart,

I think we've discussed this before.

If you use DEFINE POPUP to create the menu from which the user will make the choice, then the menu will automatically close whenever the user clicks outside it, even it they are outside your application.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike L,

Good memory! Yes indeed we discussed the toolbar before. Due to priorities I than was unable to go further with that.
Now, with my new application, I try to fix all these little left issues.
I agree with you that a define popup has the functionality as I am looking for but than there is only a menu available. The nice thing of instanciating a form is that you can put on it other controls which makes it some more flexible.

-Bart
 
Put in:
**form.Deactivate()
Thisform.release

This will release the form if you click outside the form..
 
Sorry: did not see the MODAL part. Will not work... let me think about this.....
 
ImagineCorp,

I was also going to suggest putting code in the Deactivate. But then I read this in the Help:

VFP Help said:
The Activate and Deactivate events occur only when you are moving the focus within an application. Moving focus to or from a form in another application does not trigger either event.

This applies both to modal and modeless forms.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Mike:

In modeless forms the deactivate will run when the form loses focus(). A mouse click outside the form will run the deactivate event.

Just tested to be a 100% sure and if Modeless, the above code works
Moving focus to or from a form in another application does not trigger either event.
I would read that to mean another app i.e. word, another exe etc.
 
Bart:
Make your form Modeless,
Release the form in the deactivate event.
The form will be released if another form is activated, focus moved from your (menu) form to another, some thing outside the form clicked etc.

IMO, there is no way to detect a mouse click outside a modal form without a lot of complicated code.
 
Imaginecorp,

I would read that to mean another app i.e. word, another exe etc.

But that's what Bart was asking for (when he said "outside main vfp-window").

But you're right. In a modal form, the Deactivate never fires. If the form is modeless, it fires when you click outside the form, but only within VFP.

But the event never fires if you click in another app, so making the form modeless won't solve the problem (assuming I've understood the problem correctly).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Gents,

Thanks so far for your input.
Especially 'playing' with some events might solve my problem.
In the other hand I wonder, assuming I remain with the modal form:

Once in the modal form, processes wil be treated somewhere by an event or method of that form.

My simple reason for having a modal form is that it automaticly disables all other controls like e.g. menus, toolbars etc.

So I have to built in kind of wait-status in which continuously is checked for a mouseclick not inside the form as long as no selction was made on that form.
Remember I created that form to interface with the user for a certain action e.g. make selection from several sort-options or make selection from several search options etc.

-Bart
 
There is no way to detect a mouse click outside a Modal form (IMO) unless you use the API call like Ezopaci suggested

outside main vfp-window

You really do not want to do this. When users move to another application and then return, they expect it to be in the same state when they left. Same forms displayed etc. It is confusing when the screen has changed.

To disable the toolbar and any other form opened is pretty easy:
Code:
***In your “Menu” form’s Activate Event:
For x = 1 To _Screen.FormCount
	If _Screen.Forms(x).Caption <> This.Caption
		_Screen.Forms(x).Enabled = .F.
	Endif
Endfor
Set Skip Of Menu _Msysmenu .T.

***In the query unload of the "Menu" form
For x = 1 To _Screen.FormCount
	If _Screen.Forms(x).Caption <> This.Caption
		_Screen.Forms(x).Enabled = .T.
	Endif
Endfor
Set Skip Of Menu _Msysmenu .F.

This idea of using a form as a Menu brings back memories of the DOS days and seems pretty interesting.

“Menu” form is Modeless.

Here is Scenario 1 :
Application starts. The "Menu" forms automatically pops up. Or the user selects “Menu” from either a Toolbar or Main Menu Pads to display the form.

In addition to the Activate and Query Unload, put the following in

Code:
*Menuform.Deactivate()
For x = 1 To _Screen.FormCount
	If _Screen.Forms(x).Caption <> This.Caption
		_Screen.Forms(x).Enabled = .T.
	Endif
Endfor
Set Skip Of Menu _Msysmenu .F.
Thisform.release

Put the code in a Method of the form with the exception of Thisform.Release and call this method from Activate, Deactivate & Query Unload.

Scenario 2:

You could even have the "Menu" form open after another form closes and shut it down when it loses the focus by user action. i.e. clicking outside this form, selecting a Menu or toolbar etc.

For this scenario Do not put code in the “menu” form Activate, Deactivate or Query unload

If using a form Class for your forms
In the form class, in deactivate, you can put a simple Do Form MenuForm to start the "Menu" Form.
But make sure you put a switch as well and wrap the Do Form... This way if the deafult behavour is not need set the switch to .F.

In the "Menu" form Deactivate, all that is required is
Thisform.release

As always the code I have suggested will have to be tested and fine tuned to suit your needs.

Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top