Private Sub Form_Load()
CloseWindow "notepad"
End Sub
Sub CloseWindow(ByVal partialWindowCaption$)
Dim Whnd&, L&, Nam$
partialWindowCaption = LCase$(partialWindowCaption)
Whnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
Do While Whnd <> 0
If IsWindow(Whnd) Then
L = GetWindowTextLength(Whnd)
If L > 0 Then
Nam = Space$(L + 1)
L = GetWindowText(Whnd, Nam, L + 1)
Nam = LCase$(Left$(Nam, Len(Nam) - 1))
If InStr(Nam, partialWindowCaption) Then
EndTask Whnd
Exit Do
End If
End If
End If
Whnd = GetWindow(Whnd, GW_HWNDNEXT)
DoEvents
Loop
End Sub
Private Sub EndTask(Whnd As Long)
If Whnd = Form1.hwnd Or _
GetWindow(Whnd, GW_OWNER) _
= Form1.hwnd Then End
If (GetWindowLong(Whnd, GWL_STYLE) _
And WS_DISABLED) Then Exit Sub
PostMessage Whnd, WS_CANCELMODE, 0, 0&
PostMessage Whnd, WM_CLOSE, 0, 0&
End Sub