VB6 handlers Help

5 pts.
Tags:
Visual Basic 6
I wanna write a code for capturing images from hardware devices on my PC , when i CLICK the button on tht device chk ma code n give feedbacks pls Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long Private Declare Function capDriverConnect Lib "capDriverConnect.dll" (ByVal hwnd As Long, ByVal iIndex As Long) As Long Private Declare Function capSetCallbackOnFrame Lib "capSetCallbackOnFrame.dll" (ByVal hwnd As Long, ByVal fpProc As Long) As Long Private Declare Function capPreview Lib "capPreview.dll" (ByVal hwnd As Long, ByVal f As Boolean) As Long Private Sub Form_Load() Dim mCapHwnd As Long Dim drvres As Long Dim callbck As Long Dim prev As Long mCapHwnd = capCreateCaptureWindow("WebcamCapture", 0, 0, 0, 640, 480, Me.hwnd, 0) 'Bval = capDriverConnect() 'SendMessage mCapHwnd, Connect, 0, 0 'SendMessage mCapHwnd, GET_FRAME, 0, 0 'SendMessage mCapHwnd, Copy, 0, 0 If mCapHwnd <> 0 Then drvres = capDriverConnect(hwnd, 0) If drvres <> 0 Then callbck = capSetCallbackOnFrame(hwnd, grabber_CallbackProc) If callbck <> 0 Then prev = capPreview(hwnd, True) If prev <> 0 Then MsgBox ("ERROR4") End If Else MsgBox ("ERROR3") End If Else MsgBox ("ERROR2") End If Else MsgBox ("ERROR1") End If Picture1.Picture = Clipboard.GetData SavePicture Picture1.Image, "C:Documents and Settingsvishalpicture.bmp" 'SendMessage mCapHwnd, DISCONNECT, 0, 0 End Sub thank you -Vishal

Answer Wiki

Thanks. We'll let you know when a new response is added.

You didn’t say whether this code is working or not.

Just a couple of comments:

- ERROR1, ERROR2, etc… are meaningless, you should replace that messages.
- You have all of your code in the Form_Load event, so the program will start and will immediately take and save the picture, and will disconnect the cam, so no more pictures can be taken unless you restart the program. You should use some buttons to control when the picture is taken, saved and when the cam should be disconnected.

I wrote a similar program a few months ago, just to make some tests. The only functions I used were SendMessage from ‘User32′ and capCreateCaptureWindow from ‘avicap32.dll’.

Here is the code, in case it helps in some way:

<pre>Private Declare Function SendMessage Lib “USER32″ Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function capCreateCaptureWindow Lib “avicap32.dll” Alias “capCreateCaptureWindowA” (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long

Private mCapHwnd As Long

Private Const CONNECT As Long = 1034
Private Const DISCONNECT As Long = 1035
Private Const GET_FRAME As Long = 1084
Private Const COPY As Long = 1054

Dim continue As Boolean

Sub STOPCAM()
DoEvents
SendMessage mCapHwnd, DISCONNECT, 0, 0
End Sub

Sub STARTCAM()
mCapHwnd = capCreateCaptureWindow(“WebcamCapture”, 0, 0, 0, 640, 480, Me.hwnd, 0)
DoEvents
SendMessage mCapHwnd, CONNECT, 0, 0

End Sub

Private Sub Command1_Click()
SendMessage mCapHwnd, GET_FRAME, 0, 0
SendMessage mCapHwnd, COPY, 0, 0
Picture2.Picture = Clipboard.GetData
SavePicture Picture2.Image, “C:\picture.bmp”
End Sub

Private Sub Command2_Click()
STARTCAM
continue = True
Do While continue
SendMessage mCapHwnd, GET_FRAME, 0, 0
SendMessage mCapHwnd, COPY, 0, 0
Picture1.Picture = Clipboard.GetData
DoEvents
Loop
End Sub

Private Sub Command3_Click()
STOPCAM
continue = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
If continue Then
continue = False
STOPCAM
End If
End Sub</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Vishal11
    [...] IT answers created an interesting post today on VB6 handlers HelpHere’s a short outlineNew Question Created by Vishal11 [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following