User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 397,697 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,520 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser:
Jan 7th, 2005
Views: 28,046
This shows you how to create a Windows GUI program in BCX basic and embed the Media Player in the form. It will give you a fully functional player with a 30k executable size for your MP3 files. The needed header files and library files are included in the BCX download. The ATL.DLL and WMPlayer.OCX are usually supplied with Windows and are in the System32 folder.
qbasic Syntax | 4 stars
  1. ' embeds the Windows Media Player ACTIVEX control within a BCX Form
  2. ' original PBWIN code by Jose Roca, modified by Kevin Diggins and
  3. ' Mike Henning for BCX, COM binding credit goes to Ljubisa Knezevic
  4. ' requires Windows Media Player, Automatic Template Libraries are in ATL.DLL
  5. ' needs BCX basic ver 5.05.05 or later, download free package from:
  6. ' http://www.rjpcomputing.com/programming/bcx/devsuite.html
  7. ' you can play MP3 WMA MID and WAV files and more
  8.  
  9. $LIBRARY <oleaut32.lib>
  10. $LIBRARY <uuid.lib>
  11. #include <oaidl.h>
  12.  
  13. ' this generates WinMain(), sets the Classname and the scalefactor
  14. GUI "MediaPlayer4", PIXELS
  15.  
  16. CONST IDC_CTRL = 1001
  17. CONST IDC_Btn1 = 1002
  18.  
  19. GLOBAL hWmp AS HWND
  20. GLOBAL Form AS HWND
  21. GLOBAL Btn1 AS HWND
  22.  
  23. GLOBAL pUnk AS IUnknown PTR
  24. GLOBAL objWmp AS Object
  25. GLOBAL Pth$ ' string
  26.  
  27.  
  28. ' required to create the form and it's components
  29. SUB FORMLOAD
  30. DIM RAW Style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
  31. BCX_SHOW_COM_ERRORS(TRUE)
  32.  
  33. Pth$ = SYSDIR$ & "\atl.dll" ' path string for ATL.DLL
  34. AtlAxWinInit(lib Pth$) ' initialize ATL.DLL
  35.  
  36. Form = BCX_FORM("Embedded Media Player",0,0,450,300,Style,WS_EX_CONTROLPARENT)
  37. hWmp = BCX_CONTROL("AtlAxWin",Form,"WMPlayer.OCX",IDC_CTRL,0,0,0,0)
  38. Btn1 = BCX_BUTTON("Load",Form,IDC_Btn1)
  39.  
  40. AtlAxGetControl(lib Pth$, hWmp, &pUnk)
  41. objWmp = BCX_DispatchObject(pUnk, TRUE)
  42.  
  43. SHOW(Form)
  44. END SUB
  45.  
  46.  
  47. ' code between BEGIN EVENTS/END EVENTS takes care of the event messages
  48. BEGIN EVENTS
  49. DIM RAW rc AS RECT
  50.  
  51. SELECT CASE CBMSG
  52.  
  53. CASE WM_SYSCOMMAND
  54. ' keeps the program from remaining in memory
  55. IF (wParam & 0xFFF0) = SC_CLOSE THEN
  56. SendMessage(hWnd, WM_DESTROY, wParam, lParam)
  57. EXIT FUNCTION
  58. END IF
  59.  
  60. ' set up the OpenFileDialog and get the file's name
  61. CASE WM_COMMAND
  62. ' the load button has been clicked
  63. IF LOWORD(wParam) = IDC_Btn1 THEN
  64. DIM Filename$
  65. DIM Mask$
  66. Mask$ = "Music Files|*.mid;*.mp3;*.wma;*.wav|"
  67. ' initial dir is "D:\Music1\MP3", change for your needs
  68. Filename$ = GETFILENAME$("Open Media File",Mask$,0,Form,0,"D:\Music1\MP3")
  69. IF Filename$ > "" THEN
  70. LoadWmp (Filename$)
  71. Filename$ = ""
  72. END IF ' filename
  73. END IF ' btn1
  74.  
  75. ' take care of resizing
  76. CASE WM_SIZE
  77. IF wParam <> SIZE_MINIMIZED THEN
  78. GetClientRect (hWnd, &rc)
  79. MoveWindow(GetDlgItem(hWnd,IDC_CTRL),0,25, rc.right-rc.left,rc.bottom-rc.top-25,TRUE)
  80. END IF
  81.  
  82. ' clean up and exit properly
  83. CASE WM_DESTROY
  84. Set objWmp = Nothing
  85. PostQuitMessage(0)
  86. EXIT FUNCTION
  87.  
  88. END SELECT
  89.  
  90. END EVENTS
  91.  
  92.  
  93. ' load the music file
  94. SUB LoadWmp (Filename$)
  95. objWmp.url = Filename$
  96. END SUB
  97.  
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 1:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC