View Single Post
Old 07-14-2004, 03:45 PM   #1
Needstorage
Constant Bitrate
 
Needstorage's Avatar
 
Join Date: May 2004
Location: Belgium
Vehicle: Volvo XC90 2005 summum RTI
Posts: 176
My Photos: ()
Cool Embedding BSPlayer

Small tutorial on how to embed BSPlayer into your VB6 application.

Starting up BSPlayer:
- Just use Shell to start up the main BSPlayer exe and get the window handle to start:


Code:
Shell "c:\Program Files\BSPlayer\bsplayer.exe" Do DoEvents TheHandle = FindWindow("BSPlayer", "BSPlayer") Loop While TheHandle = 0

Now we have the handle, put BSPlayer in our container. That's just a fancy word for a simple picturebox. (picContainer in my example)
Now if you switch to full screen when playing a movie, it fills your container. So actually you can control its dimensions. (When I go to my main menu while playing a movie, the movie plays on in a small tumbnail-view)

Code:
SetParent TheHandle, Me.picContainer.hwnd

Now you can start manipulating the thing.

- request the status of the player:
Code:
Status = SendMessage(TheHandle, WM_BSP_CMD, BSP_GetStatus, 0 // 0 - STOP // 1 - PAUSE // 2 - PLAY // 4 - No movie open

- open a media file:
Code:
Dim cds As COPYDATASTRUCT Dim buf(1 To 255) As Byte Dim sFileName as string sFileName = "c:\media\media file.something" Call CopyMemory(buf(1), ByVal sFileName, Len(sFileName)) With cds .dwData = BSP_OpenFile .cbData = Len(sFileName) + 1 .lpData = VarPtr(buf(1)) End With Call SendMessage(TheHandle, WM_COPYDATA, 0, cds)

- pause, play, stop, fwd, back
Code:
SendMessage TheHandle, WM_BSP_CMD, BSP_Pause, 0 SendMessage TheHandle, WM_BSP_CMD, BSP_Play, 0 SendMessage TheHandle, WM_BSP_CMD, BSP_Stop, 0 SendMessage TheHandle, WM_BSP_CMD, BSP_Forw, 0 SendMessage TheHandle, WM_BSP_CMD, BSP_Rew, 0


You will also need the next declares and types and all sort of API stuff:

Code:
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Public Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long Public Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long) Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Public Type POINTAPI X As Long Y As Long End Type Public Const GWL_STYLE = (-16) Public Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME Public Const WS_MAXIMIZEBOX = &H10000 Public Const WS_MINIMIZEBOX = &H20000 Public Const WS_SYSMENU = &H80000 Public Const WM_KEYDOWN = &H100 Public Const WM_CLOSE = &H10 Public Const WM_USER = &H400 Public Const WM_COPYDATA = &H4A Public Const WM_BSP_CMD = WM_USER + 2 Public Type COPYDATASTRUCT dwData As Long ' Use this to identify your message cbData As Long ' Number of bytes to be transferred lpData As Long ' Address of data End Type Public Const BSP_OpenFile = &H10108 Public Const BSP_FS_SWITCH = 10 Public Const BSP_Play = 20 Public Const BSP_Rew = 14 Public Const BSP_Forw = 15 Public Const BSP_Pause = 21 Public Const BSP_Stop = 22 Public Const BSP_Exit = 77 Public Const BSP_Mute = 35 Public Const BSP_GetStatus = &H10102 Public Const BSP_GetFileName = &H1010B Private Enum ESetWindowPosStyles SWP_SHOWWINDOW = &H40 SWP_HIDEWINDOW = &H80 SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE SWP_NOACTIVATE = &H10 SWP_NOCOPYBITS = &H100 SWP_NOMOVE = &H2 SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering SWP_NOREDRAW = &H8 SWP_NOREPOSITION = SWP_NOOWNERZORDER SWP_NOSIZE = &H1 SWP_NOZORDER = &H4 SWP_DRAWFRAME = SWP_FRAMECHANGED HWND_NOTOPMOST = -2 End Enum Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type

Now this was just an intro on embedding BSPlayer into a VB6 project. If you guys have any questions 'bout this, shoot.

I'm using this stuff in conjunction with a lot of other API-calls to give it a true embedded look & feel. (manipulation of the positions and dimensions of the BSplayer windows, mouse cursor hiding in BSPlayer windows, catching clicks in BSPlayer windows...) So it is possible that the declares-section described has some extra API calls I forgot to clean out for this tutorial.
__________________
Needstorage
--------------------------

Who the hell is general failure?!?
And what the f@#k is he doing reading my drive C:\?
Needstorage is offline   Reply With Quote
Sponsored Links