Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image capture in Win2K 2

Status
Not open for further replies.

simonkue

MIS
Jul 9, 2002
105
GB
I have VB6 and Win2k with a web cam. I'm trying to use the Kodak image control but cannot find the help file imgocxd.hlp. I understand that MS decided not to ship the help file after Win 95. I have 2 Win 95 CD's (one early, one late version) but cannot find this file in the CAB's.
Does anyone know where I can find this file so that I can work out how to use the control?
Alternatively, is there another/better control to use - ideally free!
All I want to do is capture a still image and save it to a file within a VB application.
 
VB6, W2K, Webcam? You don't need the Wang/Kodak stuff. The following thread contains my pointers to a solution...thread222-787607
 

strongm is right in that you don't need those controls but see the bottom of the second to last post in this thread222-829255 to find the help files you are looking for. Also I do not belive the scan control will be able to recognize a web cam as a scanner device unless it has a TWAIN interface.

Good Luck

 
Here, have a text dump of my example form that allows live preview of the video stream from a webcam, and can capture an image from it without any additional controls. I need to mention that, unlike most of my examples, this is not all my own work; it is heavily derived from a another source - unfortunatley I cannot find the necessary citations in my archives, so my apologies to the original author(s):
Code:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1 
   Caption         =   "Video Capture"
   ClientHeight    =   5025
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8670
   LinkTopic       =   "Form1"
   ScaleHeight     =   5025
   ScaleWidth      =   8670
   StartUpPosition =   3  'Windows Default
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   4080
      Top             =   2280
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "Save Image"
      Height          =   495
      Left            =   6128
      TabIndex        =   5
      Top             =   4320
      Width           =   1215
   End
   Begin VB.CommandButton cmdStop 
      Caption         =   "Stop Preview"
      Height          =   495
      Left            =   3728
      TabIndex        =   4
      Top             =   4320
      Width           =   1215
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "Start Preview"
      Height          =   495
      Left            =   1328
      TabIndex        =   3
      Top             =   4320
      Width           =   1215
   End
   Begin VB.PictureBox picCapture 
      Height          =   3495
      Left            =   3840
      ScaleHeight     =   229
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   285
      TabIndex        =   1
      Top             =   600
      Width           =   4335
   End
   Begin VB.ListBox lstDevices 
      Height          =   3180
      Left            =   240
      TabIndex        =   0
      Top             =   840
      Width           =   3255
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      Caption         =   "Available Devices"
      Height          =   255
      Left            =   240
      TabIndex        =   2
      Top             =   600
      Width           =   3255
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const WM_CAP As Integer = &H400

Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Long = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Long = WM_CAP + 30

Const WM_CAP_SET_PREVIEW As Long = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Long = WM_CAP + 52
Const WM_CAP_SET_SCALE As Long = WM_CAP + 53
Const WS_CHILD As Long = &H40000000
Const WS_VISIBLE As Long = &H10000000
Const SWP_NOMOVE As Long = &H2
Const SWP_NOSIZE As Integer = 1
Const SWP_NOZORDER As Integer = &H4
Const HWND_BOTTOM As Integer = 1

Dim iDevice As Long  ' Current device ID
Dim hHwnd As Long ' Handle to preview window

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 SetWindowPos Lib "user32" (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
Private Declare Function DestroyWindow Lib "user32" (ByVal hndw As Long) As Boolean
Private Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Integer, ByVal hWndParent As Long, ByVal nID As Long) As Long
Private Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Long, ByVal lpszName As String, ByVal cbName As Long, ByVal lpszVer As String, ByVal cbVer As Long) As Boolean

Private Sub cmdSave_Click()
    Dim bm As Image
    
    ' Copy image to clipboard
    SendMessage hHwnd, WM_CAP_EDIT_COPY, 0, 0
    ClosePreviewWindow

    picCapture.Picture = Clipboard.GetData
    
    CommonDialog1.CancelError = True
    CommonDialog1.FileName = "Webcam1"
    CommonDialog1.Filter = "Bitmap |*.bmp"
    
    On Error GoTo NoSave
    CommonDialog1.ShowSave
    
    SavePicture picCapture.Image, CommonDialog1.FileName
NoSave:
    cmdStop.Enabled = False
    cmdSave.Enabled = False
    cmdStart.Enabled = True
End Sub

Private Sub cmdStart_Click()
    iDevice = lstDevices.ListIndex
    OpenPreviewWindow
End Sub

Private Sub cmdStop_Click()
    ClosePreviewWindow
    cmdStop.Enabled = False
    cmdSave.Enabled = False
    cmdStart.Enabled = True
End Sub

Private Sub Form_Load()
    LoadDeviceList
    
    If lstDevices.ListCount > 0 Then
        lstDevices.Selected(0) = True
    Else
    cmdStart.Enabled = False
        lstDevices.AddItem ("No Device Available")
    End If
    
    cmdStop.Enabled = False
    cmdSave.Enabled = False
End Sub

Private Sub LoadDeviceList()
    Dim strName As String
    Dim strVer As String
    Dim iReturn As Boolean
    Dim x As Long
    
    x = 0
    strName = Space(100)
    strVer = Space(100)

    ' Load name of all available devices into lstDevices
    Do
        ' Get Driver name and version
        iReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
        ' If there was a device add device name to the list
        If iReturn Then lstDevices.AddItem Trim$(strName)
        x = x + 1
    Loop Until iReturn = False
End Sub

Private Sub OpenPreviewWindow()

    ' Open Preview window in picturebox
    hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, picCapture.hwnd, 0)

    ' Connect to device
    If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then

        'Set the preview scale
        SendMessage hHwnd, WM_CAP_SET_SCALE, True, 0

        'Set the preview rate in milliseconds
        SendMessage hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0

        'Start previewing the image from the camera
        SendMessage hHwnd, WM_CAP_SET_PREVIEW, True, 0

        ' Resize window to fit in picturebox
        SetWindowPos hHwnd, HWND_BOTTOM, 0, 0, picCapture.ScaleWidth, picCapture.ScaleHeight, SWP_NOMOVE Or SWP_NOZORDER

        cmdSave.Enabled = True
        cmdStop.Enabled = True
        cmdStart.Enabled = False
    Else

        ' Error connecting to device close window
        DestroyWindow hHwnd

        cmdSave.Enabled = False
    End If
 End Sub

Private Sub ClosePreviewWindow()
    ' Disconnect from device
    SendMessage hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0

    ' close window
    DestroyWindow hHwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If cmdStop.Enabled Then
        ClosePreviewWindow
    End If
End Sub

 
strongm and vb5prgmr, you have been most helpful once again.
I eventually found the help file in the 61st Win 98 CAB file and have played with the Kodak control. I can see the camera from the pgm, force it to take a picture and then save the image on the disk. Unfortunately, it is saved as a 24 bit bmp while the picture and image controls only seem to want to display 256 colour. I can convert from one to the other in Paint but this isn't a particularly clever route!
I will now work through your code supplied above to see if this helps.
Thank you both again.
 
strongm,

I've now tried your code above and I can control the web cam as well as display the image without changing anything in your code. Thanks very much.
Just one slight problem - my pc crashes most times I "Stop preview" or "Save" the image. I guess that the api calls are interfering with something so I'll investigate over the w/e.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top