Hvordan lukker jeg et bestemt program???
Fx hvis brugeren skriver "Stifinder" i Text1, så skal programmet lukke alle programmer der indeholder "Stifinder" i overskriften.
Placér følgende kode i et modul og kald herefter CloseWindow("Stifinder"):
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias _
"GetWindowTextLengthA" (ByVal hWnd 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 Const WM_CLOSE = &H10
Private SearchName As String
Public Sub CloseWindow(ByRef Caption As String)
On Error Resume Next
SearchName = Caption
EnumWindows AddressOf CloseWindowsProc, 0
End Sub
Public Function CloseWindowsProc(ByVal hWnd As Long, ByVal lParem As Long) As Long
Dim Text As String * 1024
Dim Caption As String
Dim Length As Long
CloseWindowsProc = 1
Length = GetWindowTextLength(hWnd)
If Length <= 0 Then
Caption = ""
Else
GetWindowText hWnd, Text, Length + 1
Caption = Left(Text, Length)
If InStr(1, Caption, SearchName, vbTextCompare) <> 0 Then
SendMessage hWnd, WM_CLOSE, 0, 0
CloseWindowsProc = 0
End If
End If
End Function
Håber du kan få det til at virke ...
/ Bjarke
--------------------------------------------------
[THIS IS A SIGNATURE VIRUS! PLEASE COPY IT INTO YOUR OWN SIGNATURE(S)]
--------------------------------------------------
Naturvidenskab er interessant:
http://www.unf.dk/