Results 1 to 7 of 7

Thread: Determine when program is closing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    Skopje,Macedonia
    Posts
    20
    Hello!
    Here is what i need:
    My application has the information about some opened window and when I close that window I want my application to get that information.
    I think that like the SendMessage API function sends message, the GetMessage API should solve some of my problem, but I don't know how.
    Thank you
    Emica

  2. #2
    Lively Member
    Join Date
    May 1999
    Location
    India
    Posts
    97
    Ok question 1, is that application your own? i f yes y not make it simple n use with Events??

    Cheers
    [email protected]
    " Programming today is a race between software-engineers striving to build bigger and
    better idiot-proof programs and the universe trying to produce bigger and better idiots.
    So far the universe is winning".
    :-)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    Skopje,Macedonia
    Posts
    20

    That is not my app

    I need to find out when any window in windows98 is closing, not my application, becouse my application will not be closed if I dont want to.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You may check out for active applications and make an event when an application no more is active.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    Skopje,Macedonia
    Posts
    20

    The second

    I prefer the second one.
    Thank you!
    Emica

  6. #6
    Guest
    hi,

    u can use the FindWindow API, if you know the caption or the classname of the app.

    only try to locate the app with FindWindow-API, if the returned hWnd > than zero the app is still running, if the returned hWnd=0 then the app is closed =)

    Code:
    retval = FindWindow ("Enter here the CLASSNAME or", "Enter herre the CAPTION"
    If retval = 0 Then
      MsgBox "App is closed"
     else
      MsgBox "App is running"
    end if
    hope that helps,
    taLON

  7. #7
    New Member
    Join Date
    Apr 2000
    Posts
    1

    determining when a process is finished in Win98

    Place the following code in a VB module

    ==========================================================

    Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" _
    Alias "CreateToolhelp32Snapshot" _
    (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

    Public Declare Function ProcessFirst Lib "Kernel32" _
    Alias "Process32First" _
    (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

    Public Declare Function ProcessNext Lib "Kernel32" _
    Alias "Process32Next" _
    (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

    Public Declare Sub CloseHandle Lib "Kernel32" _
    (ByVal hPass As Long)


    Public Const TH32CS_SNAPPROCESS As Long = 2&
    Public Const MAX_PATH As Integer = 260

    Public Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * MAX_PATH
    End Type

    Sub Processes(Procs$(), NumProcesses%)
    'Pass the routine an array and an integer variable
    'The routine returns the names of all running processes, starting
    'at index number 1, up to NumProcesses%

    Dim hSnapShot As Long
    Dim uProcess As PROCESSENTRY32
    Dim r As Long

    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    NumProcesses% = 0
    If hSnapShot = 0 Then Exit Sub

    uProcess.dwSize = Len(uProcess)
    r = ProcessFirst(hSnapShot, uProcess)

    Do While r
    NumProcesses% = NumProcesses% + 1
    a$ = uProcess.szExeFile
    pos% = InStr(a$, Chr$(0))
    Procs$(NumProcesses%) = Left$(a$, pos% - 1)
    If UBound(Procs$) = NumProcesses% Then
    ReDim Preserve Procs$(NumProcesses% + 10)
    End If
    r = ProcessNext(hSnapShot, uProcess)
    Loop
    Call CloseHandle(hSnapShot)

    End Sub

    ==========================================================

    As an example of how to use the above code, place a Timer control on a form, with the following code:

    Private Sub Timer1_Timer()
    ReDim Procs$(3)
    Dim NotepadFlag As Boolean
    Call Processes(Procs$(), n%)
    Cls
    NotepadFlag = False
    For i% = 1 To n%
    Notepad% = InStr(ucase$(Procs$(i%)), "NOTEPAD")
    If Notepad% <> 0 Then
    Print "Notepad is running": NotepadFlag = True
    Exit For
    End If
    Next i%
    If Not NotepadFlag Then Print "Notepad is not running"
    End Sub

    Run the program, and open and close the Windows Notepad program.Each time the Timer fires, it will enumerate the processes running under Win98, and notify you as to whether Windows Notepad is running or not.

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