How To Prevent Multiple Instances of an ApplicationLast reviewed: February 18, 1998Article ID: Q109059 |
2.5x 2.6x 3.00 5.00
WINDOWS
kbinterop kbtool kbprg kbcode kbhowto
The information in this article applies to: - Microsoft Visual FoxPro for Windows, versions 3.0, 5.0 - Microsoft FoxPro for Windows, versions 2.5x, 2.6x
SUMMARYThe program shown below demonstrates how to stop a second instance of the same FoxPro window from being started by using the Windows application programming interface (API) function FindWindow() to test if a given window name already exists. The FindWindow() function can be accessed by including FOXTOOLS.FLL, the library file that is supplied with FoxPro for Windows and documented in the Foxtools.hlp file. NOTE: This method does not prevent multiple instances of FoxPro for Windows from starting.
MORE INFORMATIONNOTE: This works in Windows for Workgroups 3.00, Windows 95, and Windows NT. Copy this code into a program file in FoxPro for windows. The first time you call the program, you will notice the main FoxPro window title change. The second time you run it, you will get the message that you cannot start another instance of the window. NOTE: Set the window name after you check for its existence.
SET LIBRARY TO SYS(2004)+"foxtools.fll" ADDITIVE * FindWindow() takes two parameters and returns the handle of the * window, HWND, if it was found. GetWind = RegFn("FindWindow", "CC", "I") *Set the first parameter of the call to getwind to 0, null. wclass=0 winname="My Application" apphand=CallFn(GetWind,wclass ,winname) *If the call was successful, stop processing. IF apphand<>0 WAIT WINDOW ; "You cannot start another instance of the window 'My Application'!" QUIT ENDIF MODIFY WINDOW screen TITLE "My Application" WAIT WINDOW ; "The first instance of the window 'My Application' is running." REFERENCESMicrosoft Windows Software Development Kit, "Programmer's Reference, Volume 2: Functions," page 309 Foxtools.hlp, located in the C:\Vfp\Tools
|
Additional reference words: 5.00 FoxWin VFoxWin 2.50 2.50a 2.50b 2.60 2.60a
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |