Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mutiple Fox Instances - How To Tell
Message
From
09/12/2004 07:12:46
Jon Neale
Bond International Software
Wootton Bassett, United Kingdom
 
 
General information
Forum:
Visual FoxPro
Category:
Installation, Setup and Configuration
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
00967971
Message ID:
00967983
Views:
6
Heres some code that does something similar with API. Its sort of specific to what I wanted but Im sure you can pick out the bits you need.

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 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