|
-
Jan 2nd, 2011, 02:53 PM
#10
Thread Starter
Junior Member
Re: Look for a program, if it's open, close it.
Edit: Ok, I fixed the sendmessage problem. Do double check though incase I am missing something, or can improve on something.
Alright, so I've scratched my previous method and am going with FindWindow and SendMessage WM_Close.
Here's what I have so far. Everything works until I tried using the SendMessage WM_Close API.
Code:
Option Explicit
Private Declare Function FINDWINDOW Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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 Sub Command5_Click()
'check if VLC media player is open
'if it is, close it. If not, tell me it's not open.
Dim lVLCwindowhandle As Long
Dim lVLCplaying As Long
lVLCwindowhandle = FINDWINDOW("VLC media player", vbNullString)
lVLCplaying = FindWindowEx(lVLCwindowhandle, 0&, "QWidget", vbNullString)
If lVLCplaying Then
SendMessage lVLCplaying, WM_CLOSE, vbNull, vbNull '<--- this is where the problem was, I had forgotten to write "vbNull" x2
MsgBox "VLC has been closed.", vbInformation, "Error"
Else
MsgBox "VLC is not open.", vbInformation, "Info"
End If
End Sub
Thanks in advance.
Last edited by Arkim; Jan 2nd, 2011 at 03:17 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|