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.
' embeds the Windows Media Player ACTIVEX control within a BCX Form ' original PBWIN code by Jose Roca, modified by Kevin Diggins and ' Mike Henning for BCX, COM binding credit goes to Ljubisa Knezevic ' requires Windows Media Player, Automatic Template Libraries are in ATL.DLL ' needs BCX basic ver 5.05.05 or later, download free package from: ' http://www.rjpcomputing.com/programming/bcx/devsuite.html ' you can play MP3 WMA MID and WAV files and more $LIBRARY <oleaut32.lib> $LIBRARY <uuid.lib> #include <oaidl.h> ' this generates WinMain(), sets the Classname and the scalefactor GUI "MediaPlayer4", PIXELS CONST IDC_CTRL = 1001 CONST IDC_Btn1 = 1002 GLOBAL hWmp AS HWND GLOBAL Form AS HWND GLOBAL Btn1 AS HWND GLOBAL pUnk AS IUnknown PTR GLOBAL objWmp as Object GLOBAL Pth$ ' string ' required to create the form and it's components SUB FORMLOAD DIM RAW Style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN BCX_SHOW_COM_ERRORS(TRUE) Pth$ = SYSDIR$ & "\atl.dll" ' path string for ATL.DLL AtlAxWinInit(lib Pth$) ' initialize ATL.DLL Form = BCX_FORM("Embedded Media Player",0,0,450,300,Style,WS_EX_CONTROLPARENT) hWmp = BCX_CONTROL("AtlAxWin",Form,"WMPlayer.OCX",IDC_CTRL,0,0,0,0) Btn1 = BCX_BUTTON("Load",Form,IDC_Btn1) AtlAxGetControl(lib Pth$, hWmp, &pUnk) objWmp = BCX_DispatchObject(pUnk, TRUE) SHOW(Form) END SUB ' code between BEGIN EVENTS/END EVENTS takes care of the event messages BEGIN EVENTS DIM RAW rc AS RECT SELECT CASE CBMSG CASE WM_SYSCOMMAND ' keeps the program from remaining in memory IF (wParam & 0xFFF0) = SC_CLOSE THEN SendMessage(hWnd, WM_DESTROY, wParam, lParam) EXIT FUNCTION END IF ' set up the OpenFileDialog and get the file's name CASE WM_COMMAND ' the load button has been clicked IF LOWORD(wParam) = IDC_Btn1 THEN DIM Filename$ Dim Mask$ Mask$ = "Music Files|*.mid;*.mp3;*.wma;*.wav|" ' initial dir is "D:\Music1\MP3", change for your needs Filename$ = GETFILENAME$("Open Media File",Mask$,0,Form,0,"D:\Music1\MP3") IF Filename$ > "" THEN LoadWmp (Filename$) Filename$ = "" END IF ' filename END IF ' btn1 ' take care of resizing CASE WM_SIZE IF wParam <> SIZE_MINIMIZED THEN GetClientRect (hWnd, &rc) MoveWindow(GetDlgItem(hWnd,IDC_CTRL),0,25, rc.right-rc.left,rc.bottom-rc.top-25,TRUE) END IF ' clean up and exit properly CASE WM_DESTROY Set objWmp = Nothing PostQuitMessage(0) EXIT FUNCTION END SELECT END EVENTS ' load the music file SUB LoadWmp (Filename$) objWmp.url = Filename$ END SUB
About the Author