"Jensen" <cabsoft@cabsoft.dk> wrote in message
news:3c3df287$0$5460$edfadb0f@dspool01.news.tele.dk...
> Hi NG.
>
> Hvordan lukker man en 3.parts applikation via VB, f.eks.
> Notepad ?
>
> Jensen, Denmark
Hej Jensen
Nedenstående kodestump lukker notepad via API kaldet
PostMessage.
' --------- KODE START
Option Compare Database
Option Explicit
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib _
"user32" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const WM_CLOSE = &H10
Private Sub KillNotePad()
Dim WinWnd As Long, Ret As String
Ret = InputBox("Enter the exact window title:" + _
Chr$(13) + Chr$(10) + _
"Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then
MsgBox "Couldn't find the window ..."
Exit Sub
End If
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
Når den spørger om navnet på programmet, skal det være 100%'
præcist det der står i Taskbaren. F.eks. Untitled - Notepad, hvis
du ønsker at lukke notepad (og bruger en engelsk Windows).
Håber du kan bruge det til noget
--
Mikkel Bundgaard
IT University of Copenhagen
http://officehelp.gone.dk
Codito, Ergo Sum