Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To check , My Exe is running or not
Message
From
27/10/2004 06:50:20
Jon Neale
Bond International Software
Wootton Bassett, United Kingdom
 
 
To
27/10/2004 03:16:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00954781
Message ID:
00954808
Views:
15
Hi Rajesh,

You can loop through the open windows and check the window names looking for your exe. So the window name for this window would be "Universal Thread".

This code will need some tidying as its what I use in my app and their is some specific stuff for my app but all you should need to do is pass in the name of the window (from your exe) and it will tell you if its running or not.

Hope this makes some sense.

Jon

FUNCTION x_payrun
LPARAMETERS p_title,p_thread
* p_thread is used to check to see if the window has been closed

LOCAL llThread

IF EMPTY(p_title)
RETURN -1
ENDIF

llThread = .F.
IF TYPE("p_thread") = "N"
llThread = .T.
ENDIF

#DEFINE GW_HWNDLAST 1
#DEFINE GW_HWNDNEXT 2
#DEFINE GW_CHILD 5
DO decl

LOCAL hDesktop, hFirstChild, hLastChild, rc, cWinCap, cWinClass,;
nVisible, nLeft, nTop, nRight, nBottom

hDesktop = GetDesktopWindow()
hFirstChild = GetWindow(hDesktop, GW_CHILD)
hLastChild = GetWindow(hFirstChild, GW_HWNDLAST)

hCurrent = hFirstChild
DO WHILE .T.

cWinCap = GetWinText(hCurrent)

IF (UPPER(ALLTRIM(p_title))$UPPER(ALLTRIM(cWinCap))) and IsWindowVisible(hCurrent) <> 0

* got the correct window
llReturn = hCurrent

IF llThread
IF hCurrent = p_thread
* window is still open keep solus waiting before shutting down
RETURN hCurrent
ELSE
RETURN -1
ENDIF
ELSE
* if we find it activate it before closing it
Declare Integer ShowWindow in Win32API ;
Integer hwnd, Integer nCmdShow
* Restore it to its last size and position
= ShowWindow(hCurrent,9)
EXIT
ENDIF
ENDIF

IF hCurrent = hLastChild
llReturn = -1
EXIT
ENDIF
hCurrent = GetWindow(hCurrent, GW_HWNDNEXT)
ENDDO

RETURN llReturn
*
*
*
FUNCTION GetClsName(hWindow)
LOCAL nBufsize, cBuffer
cBuffer = Repli(Chr(0), 250)
nBufsize = GetClassName(hWindow, @cBuffer, Len(cBuffer))
RETURN SUBSTR(cBuffer, 1, nBufsize)
*
*
*
FUNCTION GetWinText(hWindow)
* returns window title bar text -- Win9*/Me/XP/2000
LOCAL cBuffer, nResult
cBuffer = Space(250)
nResult = GetWindowText(hWindow, @cBuffer, Len(cBuffer))
RETURN SUBSTR(cBuffer, 1, nResult)
*
*
*
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
BitLShift(Asc(SUBSTR(lcBuffer, 2,1)), 8) +;
BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
*
*
*
PROCEDURE decl
DECLARE INTEGER GetDesktopWindow IN user32
DECLARE INTEGER GetWindow IN user32 INTEGER hwnd, INTEGER wFlag
DECLARE INTEGER GetWindowRect IN user32 INTEGER hwnd, STRING @lpRect
DECLARE INTEGER IsWindowVisible IN user32 INTEGER hWnd

DECLARE INTEGER GetWindowText IN user32;
INTEGER hwnd, STRING @lpString, INTEGER cch

DECLARE INTEGER GetClassName IN user32;
INTEGER hWnd, STRING lpClassName, INTEGER nMaxCount

DECLARE INTEGER GetLastError IN kernel32

RETURN
*
*
*
Previous
Reply
Map
View

Click here to load this message in the networking platform