



Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const WM_CLOSE = &H10
Dim strCaptions() As String
Dim lngHandle() As Long
Public Function CloseProg(strCaption As String) As Boolean
   Dim iCount As Integer
   Dim i As Integer
   Dim Pos As Integer
   Dim lngEnum As Long
   ReDim strCaptions(0)
   ReDim lngHandle(0)
   lngEnum = EnumWindows(AddressOf Callback1_EnumWindows, 0)
   For i = 0 To UBound(strCaptions)
    Pos = InStr(1, strCaptions(i), strCaption, vbTextCompare)
    If Pos > 0 Then
        SendMessage lngHandle(i), WM_CLOSE, 0, 0
        iCount = iCount + 1
    End If
   Next
   If iCount >= 1 Then
      CloseProg = True '
   Else
      CloseProg = False
   End If
End Function
Public Function Callback1_EnumWindows(ByVal hwnd As Long, _
     ByVal lpData As Long) As Long
   Dim cnt As Long
   Dim rttitle As String * 256
   cnt = GetWindowText(hwnd, rttitle, 255)
   If cnt > 0 Then
    ReDim Preserve lngHandle(UBound(strCaptions) + 1)
    ReDim Preserve strCaptions(UBound(strCaptions) + 1)
    strCaptions(UBound(strCaptions)) = Left$(rttitle, cnt)
    lngHandle(UBound(lngHandle)) = hwnd
   End If
   Callback1_EnumWindows = 1
End Function










Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 9