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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep focus on Form 2

Status
Not open for further replies.

mstec

Programmer
Oct 23, 2000
10
ZA
I am trying to create a "kiosk" application by running what is essentially an old dbase IV app in a top level VFP form. The form, however, occasionaly looses focus so that is is necessary to use a mouse click to change the focus back to the form. Since I need to eliminate the need for users to mouse click. Is there a way to maintain focus? Thanks in advance
 
What is it losing focus too? What's causing it? Is there a keyboard - why not just Alt+Tab back to the window?

If you just want to have an "obnoxious" app, you could add some code to the Deactivate() event and/or a Timer to simply, re-Activate yourself and effectively keep the user from going anywhere else (for long)!

What version of VFP are you running? - the code (API calls) would differ slightly.

Rick
 
if your talking about the form losing focus to something else in your app, then put code in lostfocus of the form to setfocus() back to the form. if you are trying to keep user from goint to another windows app, then you will need to do this from windows API calls. if you need to know how this is done, let me know. it has been awhile but I might be able to find the calls. Attitude is Everything
 
Thank you for you responses. BTW, I am using VFP6. Looks loke I will need the API calls since I am loosing focus to other apps running. Would appreciate any info on using API. Are you refering to WIN32? Thanks to all again.
 
Here is one way to keep your window on top, but I find it scary to think that you would prevent users from access to other apps. while you are running no other apps will be able to have focus

in the init of your form get your window handle
foxhwnd = GetActiveWindow() && get the window handle of this window

put a timer on your form. have it check for window focus with

hwnd = GetForegroundWindow() && get the window handle of top window
if hwnd != foxhwnd
** bring your window to focus
SetForegroundWindow(foxhwnd ) && BRING WINDOW TO FRONT
endif

here are the declares
declare integer SetForegroundWindow in win32api long lnhWnd
declare integer GetActiveWindow in win32api
Declare integer GetForegroundWindow in user32

some info on the functions

The GetActiveWindow function retrieves the window handle of the active window associated with the thread that calls the function.


The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user.

The GetForegroundWindow function returns the handle of the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.

Attitude is Everything
 
Danceman - do I need any files to implement win32api? Thanks
 
win32api is part of windows, you need nothing.

good luck Attitude is Everything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top