Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determining if an application is running
Message
From
03/06/2005 06:44:34
 
 
To
02/06/2005 14:10:59
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
01019492
Message ID:
01019753
Views:
19
Is thre a way to determine if an application is running, by "part" of its caption?
*** When passed a string (i.e., 'Microsoft Word'), return .T.
*** if the application is running. 
LPARAMETERS luApplication
LOCAL luRetVal, lnFoxHwnd, lnWindow, lnWhich, lcText, lnLen, lnRes
LOCAL ARRAY laJunk[1]

**********************************************************
*** Check that the library has been set up and open it if not already done.
**********************************************************
lnRes = ADLLS( laJunk )
IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'GetWindow', 1, -1, 1, 15 ) > 0)
  DECLARE INTEGER GetWindow IN Win32Api ;
      INTEGER lnWindow, ;
      INTEGER lnWhich
ENDIF

IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'GetWindowText', 1, -1, 1, 15 ) > 0)
  DECLARE INTEGER GetWindowText IN Win32Api ;
      INTEGER lnWindow, ;
      STRING   @lcText, ;
      INTEGER lnLen
ENDIF

IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'IsWindowVisible', 1, -1, 1, 15 ) > 0)    
  DECLARE INTEGER IsWindowVisible IN Win32Api ;
      INTEGER lnWindow
ENDIF
 
*** Loop through all the running applications
*** Find the next window in the z-order
lnWindow = GetWindow( _VFP.hWnd, 2 )
DO WHILE lnWindow # 0
  *** Only deal with windows that are not owned windows
  *** (i.e, dialogs or messageboxes) and make sure the window is visible
  IF GetWindow( lnWindow, 4 ) = 0 AND IsWindowVisible( lnWindow ) # 0
    lcText = SPACE( 254 )
    lnLen  = GetWindowText( lnWindow, @lcText, LEN( lcText ) )
     
    *** If the function was passed an Application Name, check for a match
    IF lnLen > 0
      IF UPPER( ALLTRIM( luApplication ) ) $ UPPER( ALLTRIM( lcText ) )
        RETURN .T.
      ENDIF
    ENDIF                  
  ENDIF

  *** See if there is another running application
  lnWindow = GetWindow( lnWindow, 2 )
ENDDO
 
*** we haven't found a match for the passed application name
RETURN .F.
Previous
Reply
Map
View

Click here to load this message in the networking platform