|
-
Oct 5th, 2000, 03:11 PM
#11
Addicted Member
I wrote the following in my vb application to test whether the user has closed an application (Word, Excel, Pbrush, etc.). It has worked well so far. I hope it may help.(Reply to the latter part of your post.)
Put it in a module. (I copied it directly from my app.)
Code:
-------------------------------------------
Private Declare Function GetWindow Lib "user32" (ByVal _
hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () _
As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_OWNER = 4
Private Const GW_CHILD = 5
Public Function CheckApp(ByVal AppCaption As String) As Long
'
'--------------------------------------------------------------
' Check whether an application has been closed.
' Return:0 = Not Closed; 1 = Closed
¡® It¡¯s better to use the VB keyword Like in the IF statement.
¡® AppCaption is the first few characters of the name of a window, whether shown or hidden.
'--------------------------------------------------------------
Dim lngHwnd As Long
Dim strWinText As String
Dim lngCch As Long
Dim lngReturn As Long
lngHwnd = GetDesktopWindow()
lngHwnd = GetWindow(lngHwnd, GW_CHILD)
Do
lngCch = 255
strWinText = String(255, 0)
lngReturn = GetWindowText(lngHwnd, strWinText, lngCch)
strWinText = Left(strWinText, lngReturn)
If Left(strWinText, Len(AppCaption)) = AppCaption Then
CheckApp = 0
Exit Do
End If
CheckApp = 1
lngHwnd = GetWindow(lngHwnd, GW_HWNDNEXT)
Loop Until lngHwnd = 0
End Function
-----------------------------------------
Visual Basic Professional 6.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|