Can anyone get this going in Blitz/plus/3D?

Blitz3D Forums/Blitz3D Userlibs/Can anyone get this going in Blitz/plus/3D?

Andy UK(Posted 2006) [#1]
This code works in Purebasic without a problem. Its pretty simple but i want to port it to Blitzplus or even Blitz3d if possible. It uses Avicap32.dll built in to most windows platforms. Some help would be much appreciated.

#WM_CAP_START = #WM_USER
#WM_CAP_SET_CALLBACK_FRAME = #WM_CAP_START + 5
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_SET_OVERLAY = #WM_CAP_START + 51
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_SET_SCALE = #WM_CAP_START + 53

OpenWindow(0,0,0,320,240,"cam",#PB_Window_SystemMenu|#PB_Window_WindowCentered)

If OpenLibrary(0,"avicap32.dll")
hWndC = CallFunctionFast(GetFunction(0,"capCreateCaptureWindowA"),"cap",#WS_CHILD|#WS_VISIBLE,0,0,320,240,WindowID(0),1)
EndIf

SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_SET_SCALE, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEWRATE, 24, 0)

Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver

End


markcw(Posted 2006) [#2]
tried it in b3d, it didn't want to work though. not sure if this is because of what i was doing as i was sure i had the decls right. then i gave up. you might want to use a dll from PB to do this. anyway, here is what i had.

Avicap32.decls (you need User32.decls too)
.lib "Avicap32.dll"

capCreateCaptureWindow%(lpszWindowName$,dwStyle,x,y,nWidth,nHeight,hWnd,nID):"capCreateCaptureWindowA"
capGetDriverDescription%(wDriverIndex,lpszName$,cbName,lpszVer$,cbVer):"capGetDriverDescriptionA"
Avicap32.bb
;Avicap32.dll test

;winuser.h constants
Const WM_USER = 1024
Const WS_CHILD = $40000000
Const WS_VISIBLE = $10000000

Const WM_CAP_START = WM_USER
Const WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5
Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Const WM_CAP_SET_OVERLAY = WM_CAP_START + 51
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_SCALE = WM_CAP_START + 53

Graphics3D 320,240,0,2
AppTitle "cam"
SetBuffer BackBuffer()

style=WS_CHILD+WS_VISIBLE
hWnd=Api_GetForegroundWindow()
hWndC=capCreateCaptureWindow("cap",style,0,0,320,240,hWnd,1) ;<- this crashes

Api_SendMessage(hWndC,WM_CAP_DRIVER_CONNECT,0,0)
Api_SendMessage(hWndC,WM_CAP_SET_SCALE,True,0)
Api_SendMessage(hWndC,WM_CAP_SET_PREVIEW,True,0)
Api_SendMessage(hWndC,WM_CAP_SET_PREVIEWRATE,24,0)

While Not KeyHit(1)

 Cls
 Text 0,0,""

Flip
Wend



Kev(Posted 2006) [#3]
Hi AUK, this under blitzplus could cause problems when calling WM_CAP_DRIVER_CONNECT without first setting the video captures callback function using WM_CAP_SET_CALLBACK_CAPCONTROL as the driver connect request fails. (WM_CAP_SET_SCALE and WM_CAP_SET_PREVIEW also fail) im thinking that the best way to handle this would be to wrapp it into a .dll so have full access to the captures callback.

anyways heres the blitzplus code and decls, b.t.w ive no capture hardware so unsure if this even work. i do now though that the capture window is created a child of the blitzplus window.

;
; Blitz Basic Plus Decls
;

.lib "user32.dll"
API_SendMessage%(hwnd%,Message%,wParam%,lParam%):"SendMessageA"
API_GetWindowLong%(hwnd%,nIndex%):"GetWindowLongA"

.lib "Avicap32.dll"
capCreateCaptureWindow%(lpszWindowName$,dwStyle%,x%,y%,nWidth%,nHeight%,hWnd%,nID%):"capCreateCaptureWindowA"



;
;
;

Const GWL_WNDPROC = -4

;winuser.h constants
Const WM_USER = 1024
Const WS_CHILD = $40000000
Const WS_VISIBLE = $10000000

Const WM_CAP_START = WM_USER
Const WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5
Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Const WM_CAP_SET_OVERLAY = WM_CAP_START + 51
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_SET_CALLBACK_CAPCONTROL = (WM_CAP_START+ 85)

window = CreateWindow("Capture Window",200,200,400,400,0,11) 
hWndC = QueryObject(window,1)

winproc = API_GetWindowLong(hWndC,GWL_WNDPROC)
DebugLog winproc

hWndC_API = capCreateCaptureWindow("cap",WS_CHILD Or WS_VISABLE,0,0,320,240,hWndC,0) 
DebugLog hWndC_API

DebugLog API_SendMessage(hWndC_API,WM_CAP_SET_CALLBACK_CAPCONTROL,0,winproc)
DebugLog API_SendMessage(hWndC_API,WM_CAP_DRIVER_CONNECT,0,0)
DebugLog API_SendMessage(hWndC_API,WM_CAP_SET_SCALE,True,0)
DebugLog API_SendMessage(hWndC_API,WM_CAP_SET_PREVIEW,True,0)
DebugLog API_SendMessage(hWndC_API,WM_CAP_SET_PREVIEWRATE,24,0)


; wait until the user closes one of the windows 
Repeat 
If WaitEvent()=$803 Then Exit 
Forever 

End ; bye!