Results 1 to 18 of 18

Thread: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*

  1. #1

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking [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?
    Last edited by ididntdoit; Oct 28th, 2006 at 08:22 PM.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  2. #2
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    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!)

  3. #3
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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!
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  5. #5

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Unhappy 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!
    Last edited by ididntdoit; Oct 28th, 2006 at 01:54 PM.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  6. #6
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Smile 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.
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  7. #7
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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?
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  8. #8

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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 hwndPreviousnull)[wParam:00000000 lParam:00000000]
    WM_ACTIVATE lResult:00000000
    WM_ACTIVATEAPP fActive:False dwThreadID:00000C74 [wParam:00000000 lParam00000C74]
    WM_ACTIVATEAPP lResult:00000000
    WM_KILLFOCUS hwndGetFocusnull) [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!
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  9. #9
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Smile Re: 'Talk' with Windows Media Player *please help*

    VB Code:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. 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
    4.  
    5. Const MEDIA_STOP = 13
    6. Const WM_APPCOMMAND = &H319
    7.  
    8. Private Sub Command1_Click()
    9. Dim WinWnd As Long
    10. WinWnd = FindWindow(vbNullString, "Windows Media Player")
    11. If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    12. SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_STOP * &H10000)
    13. End Sub

    Edit : This works for me , for Media Player 9
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  10. #10

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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*

    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  11. #11
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: 'Talk' with Windows Media Player *please help*

    I don't know except these :

    VB Code:
    1. Const MEDIA_NEXTTRACK = 11
    2. Const MEDIA_PREVIOUSTRACK = 12
    3. Const MEDIA_STOP = 13
    4. Const MEDIA_PLAY_PAUSE = 14

    Search , you may find more. , mark this as resolved if it is !!!
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  12. #12
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: 'Talk' with Windows Media Player *please help*

    BTW , thanks for your cookies
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  13. #13

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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?



    Thread Resolved
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  14. #14
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: [Resolved - thanx to msayed2004]'Talk' with Windows Media Player *please help*

    Chocolate brownie , WOW , YES YES YES
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  15. #15

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. 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
    4. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    5.  
    6. Const MEDIA_STOP = 13
    7. Const WM_APPCOMMAND = &H319
    8. Const MEDIA_NEXTTRACK = 11
    9. Const MEDIA_PREVIOUSTRACK = 12
    10. Const MEDIA_PLAY_PAUSE = 14
    11.  
    12. Dim QwertY As Integer
    13. Dim blFlg As Boolean
    14. Dim WinWnd As Long
    15.  
    16. Private Sub Timer1_Timer()
    17. If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(81) = -32768) And Not blFlg Then
    18.      WinWnd = FindWindow(vbNullString, "Windows Media Player")
    19.      If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    20.      SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_PLAY_PAUSE * &H10000)
    21.      Timer2.Enabled = True
    22.      blFlg = True
    23. End If
    24. If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(87) = -32768) And Not blFlg Then
    25.      WinWnd = FindWindow(vbNullString, "Windows Media Player")
    26.      If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    27.      SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_STOP * &H10000)
    28.      Timer2.Enabled = True
    29.      blFlg = True
    30. End If
    31. If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(83) = -32768) And Not blFlg Then
    32.      WinWnd = FindWindow(vbNullString, "Windows Media Player")
    33.      If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    34.      SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_NEXTTRACK * &H10000)
    35.      Timer2.Enabled = True
    36.      blFlg = True
    37. End If
    38. If (GetAsyncKeyState(162) = -32768) And (GetAsyncKeyState(160) = -32768) And (GetAsyncKeyState(65) = -32768) And Not blFlg Then
    39.      WinWnd = FindWindow(vbNullString, "Windows Media Player")
    40.      If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    41.      SendMessage WinWnd, WM_APPCOMMAND, 0&, ByVal (MEDIA_PREVIOUSTRACK * &H10000)
    42.      Timer2.Enabled = True
    43.      blFlg = True
    44. End If
    45. End Sub
    46.  
    47. Private Sub Timer2_Timer()
    48. blFlg = False
    49. Timer2.Enabled = False
    50. 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*
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  16. #16
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    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:
    1. Private Const MOD_ALT = &H1
    2. Private Const MOD_CONTROL = &H2
    3. Private Const MOD_SHIFT = &H4
    4. Private Const PM_REMOVE = &H1
    5. Private Const WM_HOTKEY = &H312
    6. Private Type POINTAPI
    7.     x As Long
    8.     y As Long
    9. End Type
    10. Private Type Msg
    11.     hWnd As Long
    12.     Message As Long
    13.     wParam As Long
    14.     lParam As Long
    15.     time As Long
    16.     pt As POINTAPI
    17. End Type
    18. Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    19. Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
    20. 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
    21. Private Declare Function WaitMessage Lib "user32" () As Long
    22. Private bCancel As Boolean
    23. Private Sub ProcessMessages()
    24.     Dim Message As Msg
    25.     'loop until bCancel is set to True
    26.     Do While Not bCancel
    27.         'wait for a message
    28.         WaitMessage
    29.         'check if it's a HOTKEY-message
    30.         If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
    31.             'minimize the form
    32.             WindowState = vbMinimized
    33.         End If
    34.         'let the operating system process other events
    35.         DoEvents
    36.     Loop
    37. End Sub
    38. Private Sub Form_Load()
    39.     'KPD-Team 2000
    40.     'URL: [url]http://www.allapi.net/[/url]
    41.     'E-Mail: [email][email protected][/email]
    42.     Dim ret As Long
    43.     bCancel = False
    44.     'register the Ctrl-F hotkey
    45.     ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
    46.     'show some information
    47.     Me.AutoRedraw = True
    48.     Me.Print "Press CTRL-F to minimize this form"
    49.     'show the form and
    50.     Show
    51.     'process the Hotkey messages
    52.     ProcessMessages
    53. End Sub
    54. Private Sub Form_Unload(Cancel As Integer)
    55.     bCancel = True
    56.     'unregister hotkey
    57.     Call UnregisterHotKey(Me.hWnd, &HBFFF&)
    58. End Sub


    Copied from API Guide
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  17. #17

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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!
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  18. #18

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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!!!
    Attached Files Attached Files
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width