Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remotely Control Windows Media Player (vb6) 2

Status
Not open for further replies.

TuckWat

Programmer
Aug 9, 2005
2
US
I've been struggling to find a way to control Windows Media Player Remotely (so press a button on my form, play next song in WMP, not in a control). I've successfully implemented this feature for iTunes + Winamp, and everytime I try and look up an answer I just find information about the WindowsMediaPlayer Control...

Anyone have any ideas? Thanks!
 
I think, by "remotely" you mean to control WMP by a foreign application, on the same computer.

If so, you may try the following code. You need to place four command buttons on the form.
___
[tt]
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Enum PlayCommands
cmdNext = &HB0000
cmdPrevious = &HC0000
cmdStop = &HD0000
cmdPlayPause = &HE0000
End Enum

Private Sub Form_Load()
Command1.Caption = "Previous"
Command2.Caption = "Play/Pause"
Command3.Caption = "Stop"
Command4.Caption = "Next"
End Sub

Private Sub Command1_Click()
ExecuteCommand cmdPrevious
End Sub
Private Sub Command2_Click()
ExecuteCommand cmdPlayPause
End Sub
Private Sub Command3_Click()
ExecuteCommand cmdStop
End Sub
Private Sub Command4_Click()
ExecuteCommand cmdNext
End Sub

Public Sub ExecuteCommand(cmd As PlayCommands)
Static ShellHookMessage As Long
If ShellHookMessage = 0 Then _
ShellHookMessage = RegisterWindowMessage("SHELLHOOK")
PostMessage -1, ShellHookMessage, 12, cmd 'broadcast
End Sub[/tt]
____

Note that a registered window message "SHELLHOOK" is being broadcasted to control Windows Media Player. This message is broadcasted when you press the "playback" control keys on the keyboard. Here the pressing of these keys is simulated using code. The message is broadcasted for all windows on the system. So other applications may also respond to these commands that are generated from your app.

If you want to control WMP specifically, you should grab the WMP window handle using FindWindow function (Class=WMPlayerApp, Title=Windows Media Player) and target all the messages directly to that window.
 
Thanks so much Hypetia. If I understand correctly, you're simulating the media keys on the keyboard (next, previous, pause/play, stop). This seems like a reasonable approach, without any conflicts because a user shouldn't have any other programs that use these keys... although possible.

I just attempted to use the FindWindow API to send commands to just WMP but failed. I even went through a tutorial ( that uses Spy++ and found out that WMP10 must work differently. I couldn't get it to log any WM_COMMANDs when pressing buttons. Once again thanks Hypertia!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top