Jeg kan ikke få koden til at virke, er der nogle der kan hjælpe mig vider.
Henrik
"Bjarke Walling Petersen" <bwp@bwp.dk> skrev i en meddelelse
news:9m342r$1vd2$1@news.cybercity.dk...
> Danlamp Teknik skrev:
> > Hejsa
> > Jeg har brug for noget kode der kan fortælle mig om eks. Calc.exe
køre/er
> > åben.
>
> Måske kan du bruge det her:
>
>
> 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 GetWindowTextLength Lib "user32" _
>         Alias "GetWindowTextLengthA" (ByVal hWnd 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 Const WM_CLOSE = &H10
>
> Private Enum xCompareMethod
>     xBinaryCompare
>     xTextCompare
> End Enum
>
> Private Sub CloseWindow(hWnd As Long)
>     If hWnd = 0 Then Exit Sub
>     SendMessage hWnd, WM_CLOSE, 0, 0
> End Sub
>
> Private Function GetWindowHWnd(WindowCaption As String, _
>                 Optional Compare As xCompareMethod) As Long
>     Dim wCaption As String
>     Dim hWnd As Long
>     Dim ln As Long
>     If IsEmpty(Compare) Then
>         Compare = xTextCompare
>     End If
>     If Compare = xTextCompare Then
>         WindowCaption = LCase$(WindowCaption)
>     End If
>     GetWindowHWnd = 0
>     hWnd = GetWindow(Me.hWnd, 0)
>     Do While hWnd <> 0
>         ln = GetWindowTextLength(hWnd)
>         wCaption = Space$(ln)
>         If GetWindowText(hWnd, wCaption, ln) > 0 Then
>             If Compare = xTextCompare Then
>                 wCaption = LCase$(wCaption)
>             End If
>             If InStr(wCaption, WindowCaption) <> 0 Then
>                 GetWindowHWnd = hWnd
>                 Exit Do
>             End If
>         End If
>         hWnd = GetWindow(hWnd, 2)
>     Loop
> End Function
>
> Private Sub Command1_Click()
>
>     ' *************************
>     ' Og sådan kan man så f.eks. gøre:
>     ' *************************
>     Dim hWnd As Long
>     hWnd = GetWindowHWnd("Lommeregner")
>     If hWnd = 0 Then
>         MsgBox "Programmet kører ikke..."
>     Else
>         MsgBox "Programmet kører..." & vbCrLf & "Handle: " & CStr(hWnd)
>         MsgBox "Programmet vil nu blive lukket!"
>         CloseWindow hWnd
>     End If
>
> End Sub
>
>
> Det skal lige siges at jeg ikke har testet det helt igennem, men jeg er
ret
> sikker på at det virker... 
>
>  - Bjarke Walling Petersen
>
>