'Hallo Gizmo...
'hier ein kleines Beispiel wie Sie die verschiedenen Anwendungen beenden können.
'Testumgebung : W98
'
'Klassennamen: 'Beispiele zum Beenden :
'ClassName = "OpusApp" ' = WinWord 7
'ClassName = "IEFrame" ' = Internet Explorer
'ClassName = "XLMAIN" ' = Excel 7
'Übergabe des Klassennamen hier für Word für dieses Beispiel...
'
'NG.: 02.02.03
Private Declare Function IsWindow Lib "user32" _
(ByVal hwnd As Long) _
As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal wCmd As Long) _
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 Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) _
As Long
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As Any) _
As Long
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Const GW_OWNER = (4)
Private Const GWL_STYLE = (-16)
Private Const WS_DISABLED = &H8000000
Private Const WM_SETFOCUS = &H7
Private Const WM_CLOSE = &H10
Private Const WM_CANCELMODE = &H1F
Private Sub Command1_Click()
Dim ClassName As String
Dim Result As Long
Dim hTitle As String
Dim tmpTitle As String
Dim mHwnd As Long
Dim TitleLen As Long
Dim EndTask As Long
ClassName = "OpusApp" ' = Word
mHwnd = ClasshWnd(ClassName)
If mHwnd = 0 Then
MsgBox "Zu beendende Anwendung ist z.Zt. nicht aktiv!", _
vbOKOnly + vbInformation, "Info..."
Exit Sub
End If
hTitle = GetWindowTitle(mHwnd)
tmpTitle = hTitle
TitleLen = InStr(tmpTitle, " -")
Debug.Print TitleLen
If TitleLen = 0 Then TitleLen = Len(tmpTitle) + 1
tmpTitle = UCase(Left(tmpTitle, TitleLen - 1))
Result = MsgBox("Anwendung " & tmpTitle & " beenden ?", _
vbYesNo + vbQuestion, _
" " & ClassName & _
" beenden")
If Result <> vbYes Then Exit Sub
With Me
EndTask = KillTask(.hwnd, mHwnd)
'
End With
If EndTask = 0 Then
MsgBox "Error : " & tmpTitle & " kann nicht beendet werden!"
End If
End Sub
Private Function KillTask(ByVal CurrentAppHwnd As Long, ByVal CloseAppHwnd As _
Long) As Long
Dim lRet As Long
If CloseAppHwnd = CurrentAppHwnd Or GetWindow(CloseAppHwnd, GW_OWNER) = _
CurrentAppHwnd Then
End
End If
If IsWindow(CloseAppHwnd) Then
If Not (GetWindowLong(CloseAppHwnd, GWL_STYLE) And WS_DISABLED) Then
If Not (GetWindowLong(CloseAppHwnd, GWL_STYLE) And WS_DISABLED) Then
lRet = PostMessage(CloseAppHwnd, WM_CANCELMODE, 0, 0&)
lRet = PostMessage(CloseAppHwnd, WM_SETFOCUS, 0, 0&)
lRet = PostMessage(CloseAppHwnd, WM_CLOSE, 0, 0&)
End If
End If
KillTask = -1
Else
KillTask = 0
End If
End Function
Private Function ClasshWnd(ByVal mClassName As String) As Long
ClasshWnd = FindWindow(mClassName, 0&)
Debug.Print ClasshWnd
End Function
Private Function GetWindowTitle(ByVal hwnd As Long) As String
Dim sBuffer As String
Dim mLen As Long
sBuffer = Space(255)
mLen = GetWindowText(hwnd, sBuffer, Len(sBuffer))
GetWindowTitle = Left(sBuffer, mLen)
End Function
'MfG
'Frank... |