Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking for Program allready running
Message
From
18/02/2000 10:35:27
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Checking for Program allready running
Miscellaneous
Thread ID:
00334069
Message ID:
00334069
Views:
64
I got this code from George Tasker originally and it did a $ to see if the program name was in the window name being checked. If your program directory was the same as your program and you double clicked on the program in explorer it would not run the program. The following severly hacked code (only slighly resembles George's orignal code but thanks alot for the start) corrects that problem but you must have at least the beggining of the window name to work properly...
* Original AUTHOR: George Tasker
* DATE: January 13, 1998 - 8:26 AM
* PURPOSE: Determines if a Windows
* application is running and returns
* the handle of the window if it is,
* otherwise returns 0. 32 bit version
* for Windows 95/NT 3.51-4
* Note 
* Original version would not load the program 
* if you double clicked on it in explorer
* because the explorer window might contain 
* part of the program window if the directory
* and the program window were the same
* (John Thornton)

LPARAMETER pcTitle

* Parameter list description
*
* pctitle - The title bar of the Window
*   Note: The title does not have to be
*   the complete title that appears
*   BUT IT MUST BE THE BEGINNING OF THE WINDOW NAME
* API Declarations
DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API;
	INTEGER hwnd, INTEGER dflag
DECLARE INTEGER GetWindowText IN Win32API ;
	INTEGER hwnd, STRING @lptstr, INTEGER cbmax

LOCAL lnhwnd, lnNext, llDone, lcTitleBar, ;
	lcSearchFor, lnTextLen
lcSearchFor = UPPER(ALLTRIM(pctitle))
lnhwnd = GetActiveWindow()
lnNext = 2
llDone = .F.
lcTitleBar = ""
DO WHILE NOT llDone
  IF NOT EMPTY(lnhwnd)
    lcTitleBar = SPACE(200) + CHR(0)
    lnTextLen = GetWindowText(lnhwnd, @lcTitleBar, 200)
    lcTitleBar = UPPER(LEFT(lcTitleBar, lnTextLen))
    * Modified by John Thornton 2/16/00
    * Changed so if you double click in explorer it will 
    * still load the program if the dir has the same name
    IF lcTitleBar = lcSearchFor
      llDone = .T.
    ELSE
      lnhwnd = GetWindow(lnhwnd, lnNext)
    ENDIF
  ELSE
    llDone = .T.
  ENDIF
ENDDO
RETURN lnhwnd
Next
Reply
Map
View

Click here to load this message in the networking platform