[Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*
I need two things for a program I'd like to write (mybe only one). What I want to do is have a hot-key that will stop/play WMP(9 series). I've got the hotkey thing worked out, but what I need to do is somehow tell WMP to Stop or Play (not Pause/play!). What code could I use to do this? I either need a) a way to actually 'talk' to WMP directly and 'tell' it to stop/play, or b) a way to simulate a key press system wide BUT, if I use option 2, I'm not sure what the ASCII of the stop/play key is that WMP responds to. Can anyone help? :ehh:
Re: 'Talk' with Windows Media Player *please help*
Go to the MS site and search for "Windows Media Player SDK". It has a few samples in it. (It's more complex than you think!)
Re: 'Talk' with Windows Media Player *please help*
You might be off by using the SendKeys function.
But first you would need to find the WMP hwnd and then so it has the focus and have it simulate the pressing of PLAY/STOP.
Try this link on SendKeys function.
Re: 'Talk' with Windows Media Player *please help*
Quote:
Originally Posted by schoolbusdriver
Go to the MS site and search for "Windows Media Player SDK". It has a few samples in it. (It's more complex than you think!)
Thanx, looks promising, but haven't gotten around to installing it yet! :wave:
Re: 'Talk' with Windows Media Player *please help*
Ok, this installer is just totally effed over! It hasn't once out of about 5 attempts successfully made it even to the halfway point without errors. I've tried the sendkeys idea, but my problem is sending the keys, since the program will be as good as minimized, and sendkeys can't access a minimized window, even with AppActivate. It just don't work! It just crashes, since WMP is in the system tray. Anyone know how I can do this??? Pls!
Re: 'Talk' with Windows Media Player *please help*
What about sending messages to it , watch it with Microsoft Spy you may get the needed msg for this.
Re: 'Talk' with Windows Media Player *please help*
Do you have to control the external WMP or can you have WMP in your own program as a plugin?
Re: 'Talk' with Windows Media Player *please help*
Quote:
Originally Posted by msayed2004
What about sending messages to it , watch it with Microsoft Spy you may get the needed msg for this.
This is getting somewhere! Good idea *reputates*
These were the given messages when I clicked the button I want to mimic, now how in the heck do I use them in VB?
WM LBUTTONUP fwKeys:0000 xPos:1519 yPos:878
WM_CAPTURECHANGED hwndNewCapture:00000000[wParam:00000000 lParam:00000000]
WM_CAPTURECHANGED lResult:00000000
WM_MENUSELECT uItem:0 fuFlags:FFFF(menu was closed) hmenu:00000000[wParam:FFFF0000 lParam:0000]
WM_MENUSELECT lResult:00000000
message:0x8064[User-defined:WM_USER+31844]lRsult:00000000
WM_NCACTIVATE fActive:False[wParam:00000000 lParam:00000000]
WM_NCACTIVATE fDeactivateOK:True[Result:00000001]
WM_ACTIVATE fActive:WA_INACTIVE fMinimized:False hwndPrevious:(null)[wParam:00000000 lParam:00000000]
WM_ACTIVATE lResult:00000000
WM_ACTIVATEAPP fActive:False dwThreadID:00000C74 [wParam:00000000 lParam00000C74]
WM_ACTIVATEAPP lResult:00000000
WM_KILLFOCUS hwndGetFocus:(null) [wParam:00000000 lParam:00000000]
WM_KILLFOCUS lResult:00000000
WM_DEVICECHANGE Event:0007 dwData:00000000 [wParam:00000007 lParam:00000000]
Can you please help me??? This was a great idea, especially if you can help me make it work!
Re: 'Talk' with Windows Media Player *please help*
VB Code:
Option Explicit
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 Integer, ByVal lParam As Any) As Long
Const MEDIA_STOP = 13
Const WM_APPCOMMAND = &H319
Private Sub Command1_Click()
Dim WinWnd As Long
WinWnd = FindWindow(vbNullString, "Windows Media Player")
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_STOP * &H10000)
End Sub
Edit : This works for me , for Media Player 9
Re: 'Talk' with Windows Media Player *please help*
*gives you a cookie*
This is EXACTLY what I've ben looking for for a long time!!! How did you determine the values so I can mimic this code for play/pause, volume up/down, and next/last song? I will re-reputate as soon as I've spread some around first!
*gives you another cookie*
*gives you a recipe for the cookies and ingredient money*
:p :p :p :p :p :p :p :p :p :p :p :p :p :p :p :p :p :p :p
Re: 'Talk' with Windows Media Player *please help*
I don't know except these :
VB Code:
Const MEDIA_NEXTTRACK = 11
Const MEDIA_PREVIOUSTRACK = 12
Const MEDIA_STOP = 13
Const MEDIA_PLAY_PAUSE = 14
Search , you may find more. :) , mark this as resolved if it is !!!
Re: 'Talk' with Windows Media Player *please help*
BTW , thanks for your cookies :) ;)
Re: 'Talk' with Windows Media Player *please help*
Quote:
Originally Posted by msayed2004
BTW , thanks for your cookies :) ;)
Thanx, I had just found these on another site. AFAIK, these are the only ones.
BTW, do u like brownies? :p :p :lol: ;)
Thread Resolved
Re: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*
Chocolate brownie , WOW , YES YES YES
Re: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*
Quote:
Originally Posted by msayed2004
Chocolate brownie , WOW , YES YES YES
kk, *gives you a brownie*
Here, I just whipped this up before I go to bed (it's already 10 to 10 my time)
VB Code:
Option Explicit
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 Integer, ByVal lParam As Any) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Const MEDIA_STOP = 13
Const WM_APPCOMMAND = &H319
Const MEDIA_NEXTTRACK = 11
Const MEDIA_PREVIOUSTRACK = 12
Const MEDIA_PLAY_PAUSE = 14
Dim QwertY As Integer
Dim blFlg As Boolean
Dim WinWnd As Long
Private Sub Timer1_Timer()
If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(81) = -32768) And Not blFlg Then
WinWnd = FindWindow(vbNullString, "Windows Media Player")
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_PLAY_PAUSE * &H10000)
Timer2.Enabled = True
blFlg = True
End If
If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(87) = -32768) And Not blFlg Then
WinWnd = FindWindow(vbNullString, "Windows Media Player")
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_STOP * &H10000)
Timer2.Enabled = True
blFlg = True
End If
If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(83) = -32768) And Not blFlg Then
WinWnd = FindWindow(vbNullString, "Windows Media Player")
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_NEXTTRACK * &H10000)
Timer2.Enabled = True
blFlg = True
End If
If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(65) = -32768) And Not blFlg Then
WinWnd = FindWindow(vbNullString, "Windows Media Player")
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_PREVIOUSTRACK * &H10000)
Timer2.Enabled = True
blFlg = True
End If
End Sub
Private Sub Timer2_Timer()
blFlg = False
Timer2.Enabled = False
End Sub
Timer1 is set at 1ms intervals, timer2 is at 200ms intervals (w/o this, you can't push the button on and off fast enough to avoid it being caught two - ten times!). I'll just run this in the background invisibly, and voila, a WMP tray control with hot-keys (I know there is a WMP tray control, but I need one w/ hot-keys!) Thanx again! (note I gave full credit to you in the thread title ;))
*eats a brownie my self*
*LOLs with joy*
*goes to bed*
Re: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*
You can register hot keys by this (better than GetAsyncKeyState which may be stopped by any anti-spyware) :
VB Code:
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Sub ProcessMessages()
Dim Message As Msg
'loop until bCancel is set to True
Do While Not bCancel
'wait for a message
WaitMessage
'check if it's a HOTKEY-message
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
'minimize the form
WindowState = vbMinimized
End If
'let the operating system process other events
DoEvents
Loop
End Sub
Private Sub Form_Load()
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
Dim ret As Long
bCancel = False
'register the Ctrl-F hotkey
ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
'show some information
Me.AutoRedraw = True
Me.Print "Press CTRL-F to minimize this form"
'show the form and
Show
'process the Hotkey messages
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
'unregister hotkey
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
Copied from API Guide
Re: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*
Whatev
This way is easier and safer (that code will crash badly if not closed right).
I'm off 2 bed, but I've made a quick sample program out of this whole thing and I'll post it tomorrow. Thanx again for all your help!
1 Attachment(s)
Re: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*
O.K. people, here's the source code. Just compile and make exe, then voila! Instant WMP tray controller! Again, much thanx to msayed2004, this program is based around your code and help!
*gives you a slice of my lemon merangue pie!*
DOWNLOAD IT NOW!!!