-
Sheesh..seems I’ve managed to stump the experts here!
What I’m Trying to do in my VB networked program is use ShellExecute to launch the Windows Media Player, and then shut it down from the program.
First the code to LAUNCH:
Dim ItemFile As String
ItemFile = "Training1.mpg"
Call ShellExecute(hwnd, "Open", ItemFile, "", App.Path & "\Items\", 1)
bIsPlaying = True ' SETS THE MULTIMEDIA FLAG!!!
So now I have the Media running; what I WANT to have happen is when the user clicks the “Next Item” button, code in the click event ENDS/CLOSES/KILLS the Windows Media Player!
I’ve looked at the SendMessage, TerminateProcess, and CloseHandle API calls but NONE of them work! I can't guarantee just WHERE the MediaPlayer.exe is on a Network, so If I need to find the path of the executable that is running the ShellExecute function-how do I do that?
Does ANYONE have an idea of how to simply close the MediaPlayer with code from the VB program that will work in Windows 98 AND NT 4.0?? I’d really appreciate any help. Thanks!
-
Hey matey! you're in luck I'm just building a class for Window Handling, I'll post it as soon as finished :)
Code:
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName 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 SC_CLOSE = &HF060
Private Const WM_SYSCOMMAND = &H112
Private Sub Form_Load()
Dim ItemFile$
ItemFile = "Training1.mpg"
ShellExecute(hwnd, "Open", ItemFile, "", App.Path & "\Items\", 1)
bIsPlaying = True ' SETS THE MULTIMEDIA FLAG!!!
End Sub
Private Sub Command1_Click()
Dim win&
win = FindWindow("myclassname", vbnullstring)
SendMessage win, WM_SYSCOMMAND, ByVal SC_CLOSE, ByVal 0&
End Sub
Hope it works for ya!
[Edited by Jop on 11-10-2000 at 10:11 AM]
-
No dice!
Oh man! I MUST be doing something WRONG here! I pasted your code into the form & when I run Command1_click NOTHING happens!
2 Questions:
1) the value of win is 0 (zero) below - is that correct??
win = FindWindow("myclassname", vbNullString)
SendMessage win, WM_SYSCOMMAND, ByVal SC_CLOSE, ByVal 0&
2)could there be a problem with "myclassname" -- I don't exactly know what that is?
ARRRGH! It feels SO close, but it's just not there yet! If there's something I'm leaving out please let me know & I'll be glad to put it in! My best guess is that VB can't figure out the handle of the MediaPlayer, or the NAME of the mpg?? Thanks for you help so far-looking forward to that Window Handling class!!
-
Yep, it's the myclassname :)
change the line to:
Code:
win = FindWindow("Media Player 2", "")
'It's Media Player 2 for the second edition and MPlayer for the other one, don't know which one you use
There's a way to kill a window bye it exe's path, but I don't know if you want to distribute the app (in which case you can never know where the exe is)
[Edited by Jop on 11-10-2000 at 11:13 AM]
-
Success!!
ALL RIGHT!! It worked! Yo da best!! <g> The ONLY problem I see is on older PCs on the network that MIGHT have
Mplayer instead of Media Player 2, I guess I can run the win code both times to kill off either one right?
Would there be ANY problem with the following:??
Private Sub Command1_click()
Dim win&
' first close if Mplayer2 is running
win = FindWindow("Media Player 2", vbNullString)
SendMessage win, WM_SYSCOMMAND, ByVal SC_CLOSE, ByVal 0&
' second close if Mplayer is running
win = FindWindow("MPlayer", vbNullString)
SendMessage win, WM_SYSCOMMAND, ByVal SC_CLOSE, ByVal 0&
End Sub
THANKS SO much for your help-your's is the first straight answer I've gotten;
I think where I got lost is not understanding the CLASS name for the MediaPlayer.
I REALLY appreciate the help you gave-keep up the good work!
thomas
-
No, there's no real problem with that, but this is better.
Code:
' first close if Mplayer2 is running
win = FindWindow("Media Player 2", vbNullString)
If win = 0 Then win = FindWindow("MPlayer", vbNullString) 'If Media Player 2 isn't found then set it to mplayer
If win = 0 Then Exit Sub 'stop it because none of the windows are found :(
SendMessage win, WM_SYSCOMMAND, ByVal SC_CLOSE, ByVal 0&
This should work...
Have fun!
-
Thanks!
THank you sir! Consider it done!
-
Ok I'll let you know when my class is ready, I'll publish it here.
-
Hey Thom, still want my class?
Look at
http://www.geocities.com/despotez/WH/