I've got a function to do it.

Put these in your main program and call chkrunning() to see if it is open. Got that from here years ago.

DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API INTEGER nHwnd, INTEGER nFlag
DECLARE INTEGER GetWindowText IN Win32API INTEGER nHwnd, STRING @cText, INTEGER nMax


FUNCTION chkrunning
LOCAL nSafecounter,nWin1,lFound,cSrchTitle,cCurWinTitle,nLen
*-- set your search string for the window title
SrchTitle = "Myapp titlebar"
nLen=LEN(cSrchTitle)
*-- get a starting point window ref
nWin1 = GetActiveWindow()
*-- An assumption here is that after calling GetWindow with a flag of 2 (to get 'next' *-- window), eventually the call will return a 0. In other words, the call will not *-- 'loop' around to the original window handle. For now, there is a safety catch of
*-- calling the GetWindow API only 300 times, max.
lFound = .F.
nSafecounter=0
DO WHILE NOT EMPTY(nWin1) AND nSafeCounter < 300 AND lFound=.f.
       IF NOT EMPTY(nWin1)
               cCurWinTitle = SPACE(200) + CHR(0)
               nTitleLen = GetWindowText(nWin1, @cCurWinTitle, 200)
               IF Left(cCurWinTitle,nLen) = cSrchTitle
                       lFound = .T.
               ELSE
                       *nWin1 = GetWindow(nWin1, nFlag)
                       nWin1 = GetWindow(nWin1, 2)
               ENDIF
       ENDIF
       nSafeCounter = nSafeCounter + 1
ENDDO

RETURN lFound


* Peter Cushing *
IT development and support

Signature


jerry foote wrote:
I have a program written in vfp8 running on xp. I HAVE to stop a second
instance of the program from running.

Any suggestions.

Jerry



--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to