Results 1 to 5 of 5

Thread: opening and closing programs

  1. #1

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    My program opens another program, and I'm needing to know get my program to recognize when that certain program is closed. Any help is appreciated..
    Stephen Bazemore
    Email:[email protected]

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    You would have to use a time to keep checking
    
    'finding the hwnd of a window if you know the title
    'of the window
    
    '<<<<<<<<<<<<<<<<  Bas Module Code   >>>>>>>>>>>>>>>>>
    
    'API to get the handle of a window
    
    Declare Function FindWindow Lib "user32.dll" _
    Alias "FindWindowA" (ByVal lpClassName As Any, _
    ByVal lpWindowName As Any) As Long
    
    'Parameters
    
    'lpClassName
    'The name of the window class of the window to find.
    'Pass 0 to allow the window to be of any class.
    
    'lpWindowName
    'The name of the title bar text of the window to find. '
    'Pass 0 to allow the window to have any name.
    
    
    
    '<<<<<<<<<<<<<<<<<  Form Code  >>>>>>>>>>>>>>>>>>>
    
    Option Explicit
    
    Private Sub Command1_Click()
    
    Dim hwnd As Long  ' receives handle to the found window
    
    ' Attempt to locate a window called Calculator
    ' Note how the CLng function
    ' must be used to force 0 as a Long data type.
    
    hwnd = FindWindow(CLng(0), "Calculator")  ' look for the window
    If hwnd = 0 Then  ' could not find the window
      MsgBox "Calculator is not currently running."
    Else
      MsgBox "the hwnd for Calculator is " & hwnd
    End If
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    There appears to be an API called: WaitForSingleObject

    According the documentation, this API will "simply wait for
    a process to return or a timeout to occur..."

    Could this be what you want?

    Good Luck
    DerFarm

  4. #4
    Guest
    Try this:

    Code:
    Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    Const STILL_ACTIVE = &H103
    Const PROCESS_QUERY_INFORMATION = &H400
    
    'JobtoDo - Program to run
    
    
    Sub Shell32Bit(ByVal JobToDo As String)
    
             Dim hProcess As Long
             Dim RetVal As Long
             'The next line launches JobToDo as icon,
    
             'captures process ID
             hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))
    
             Do
    
                 'Get the status of the process
                 GetExitCodeProcess hProcess, RetVal
    
                 'Sleep command recommended as well as DoEvents
                 DoEvents: Sleep 100
    
             'Loop while the process is active
             Loop While RetVal = STILL_ACTIVE
             Msgbox "App has been unloaded!"
    End Sub
    
    Usage:
    
    Private Sub Command1_Click()
    Call Shell32Bit("C:\App\App.exe")
    End Sub

  5. #5

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    Thanks guys..
    Stephen Bazemore
    Email:[email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width