请问,怎样在VB的窗口中载入摄像头的画面?就像QQ那种?

xianganh 2005-03-03 09:39:29
有几个问题请教:
1、怎样在VB的窗口中播放摄像头的画面,简单地说就是将摄像头所录的东西用VB的窗口播,就像QQ的视频聊天的那种,有没有这样的windows函数,最好能写出代码
2、有没有人知道RECT这个数据类型,能在VB中用吗?我今天用GetWindowRect这个函数,返回一个RECT数据类型的指针,我怎样定义一个RECT类型的数据结构才能取得GetWindowRect的返回值啊?在VC里面是CRECT。
谢谢
...全文
314 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sworddx 2005-03-05
  • 打赏
  • 举报
回复
第一个问题我也说不具体,控件我没用过,但是好像可以用directshow的相关api来解决。
bxf 2005-03-05
  • 打赏
  • 举报
回复
用kodak那几个控件,具体用法不会,你慢慢研究吧,好像很简单
wenquan836 2005-03-05
  • 打赏
  • 举报
回复
Option Explicit
Dim lwndC As Long ' Handle to the Capture Windows
Dim lNFrames As Long ' Number of frames captured

Sub ResizeCaptureWindow(ByVal lwnd As Long)

Dim CAPSTATUS As CAPSTATUS

'// Get the capture window attributes .. width and height
capGetStatus lwnd, VarPtr(CAPSTATUS), Len(CAPSTATUS)

'// Resize the capture window to the capture sizes
SetWindowPos lwnd, HWND_BOTTOM, 0, 0, _
CAPSTATUS.uiImageWidth, _
CAPSTATUS.uiImageHeight, _
SWP_NOMOVE Or SWP_NOZORDER

End Sub


Private Sub Form_Load()

Dim lpszName As String * 100
Dim lpszVer As String * 100
Dim Caps As CAPDRIVERCAPS

'//Create Capture Window
capGetDriverDescriptionA 0, lpszName, 100, lpszVer, 100 '// Retrieves driver info
lwndC = capCreateCaptureWindowA(lpszName, WS_CHILD Or WS_VISIBLE, 0, 0, 160, 120, Me.hwnd, 0)

'// Connect the capture window to the driver
capDriverConnect lwndC, 0

'// Get the capabilities of the capture driver
capDriverGetCaps lwndC, VarPtr(Caps), Len(Caps)

'// If the capture driver does not support a dialog, grey it out
'// in the menu bar.
If Caps.fHasDlgVideoSource = 0 Then mnuSource.Enabled = False
If Caps.fHasDlgVideoFormat = 0 Then mnuFormat.Enabled = False
If Caps.fHasDlgVideoDisplay = 0 Then mnuDisplay.Enabled = False

'// Set the video stream callback function
capSetCallbackOnVideoStream lwndC, AddressOf MyVideoStreamCallback
capSetCallbackOnFrame lwndC, AddressOf MyFrameCallback

'// Set the preview rate in milliseconds
capPreviewRate lwndC, 66

'// Start previewing the image from the camera
capPreview lwndC, True

'// Resize the capture window to show the whole image
ResizeCaptureWindow lwndC

End Sub


Private Sub Form_Unload(Cancel As Integer)

'// Disable all callbacks
capSetCallbackOnError lwndC, vbNull
capSetCallbackOnStatus lwndC, vbNull
capSetCallbackOnYield lwndC, vbNull
capSetCallbackOnFrame lwndC, vbNull
capSetCallbackOnVideoStream lwndC, vbNull
capSetCallbackOnWaveStream lwndC, vbNull
capSetCallbackOnCapControl lwndC, vbNull


End Sub


Private Sub mnuCompression_Click()
' /*
' * Display the Compression dialog when "Compression" is selected from
' * the menu bar.
' */

capDlgVideoCompression lwndC

End Sub

Private Sub mnuDisplay_Click()
' /*
' * Display the Video Display dialog when "Display" is selected from
' * the menu bar.
' */

capDlgVideoDisplay lwndC

End Sub

Private Sub mnuExit_Click()

Unload Me

End Sub

Private Sub mnuFormat_Click()
' /*
' * Display the Video Format dialog when "Format" is selected from the
' * menu bar.
' */

capDlgVideoFormat lwndC
ResizeCaptureWindow lwndC

End Sub

Private Sub mnuPreview_Click()

mnuPreview.Checked = Not (mnuPreview.Checked)
capPreview lwndC, mnuPreview.Checked

End Sub


Private Sub mnuSource_Click()
' /*
' * Display the Video Source dialog when "Source" is selected from the
' * menu bar.
' */

capDlgVideoSource lwndC

End Sub

Private Sub mnuStart_Click()
' /*
' * If Start is selected from the menu, start Streaming capture.
' * The streaming capture is terminated when the Escape key is pressed
' */
lNFrames = 0
capCaptureSequenceNoFile lwndC

End Sub
'---------------------------------------Module1
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_SYSCOMMAND = &H112
Public Const SC_MOVE = &HF010&
Public Const WM_ACTIVATE = &H6
Public Const WM_KILLFOCUS = &H8
Public Const GWL_WNDPROC = (-4)
Public Const WM_PAINT = &HF
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_SETFOCUS = &H7

Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Wndproc As Long
Function Proc(ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) _
As Long
If msg = &H7 Then Proc = 1: Exit Function
Proc = CallWindowProc(Wndproc, hwnd, msg, wp, lp)
End Function
xianganh 2005-03-04
  • 打赏
  • 举报
回复
WallesCai(算了下命,居然说我今年桃花遍地,紫溦星临头!) 能告诉我那个控件具体的用法吗?谢谢!
xianganh 2005-03-03
  • 打赏
  • 举报
回复 1
能不能说具体一点,谢谢
熊孩子开学喽 2005-03-03
  • 打赏
  • 举报
回复
问题1:找个控件吧,放在窗体里就可以用视频了,我用过一个VIDEOCAPTURE
问题2:使用VB带的API浏览器就可以看到API的参数定义了,在VB的窗体菜单中找一下"外接程序管理"就能找到
little_sheep 2005-03-03
  • 打赏
  • 举报
回复
VB也有,用API浏览器看看类型,就是RECT。

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧