Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom GDI+ class
How to change display settings: screen resolution, screen refresh rate
Obtaining names and positions for shortcuts located on the Windows Desktop
GDI+: Implementing image scrolling with inertia
Displaying dimmed window behind VFP top-level form
Storing content of the Clipboard to a bitmap file
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Displaying icons in the system tray (VFP9)
Detecting changes in connections to removable drives (VFP9)
How to print a bitmap file
How to load a user profile
How to print FoxPro form
Printing Image File, programmatically set print page orientation to landscape
Subclassing CommandButton control to create BackColor property
Windows Shell Icons displayed and exported to ICO files (Vista)
Moving shortcut to a specified position on the Windows Desktop
Custom FTP Class for Visual FoxPro application
Browsing Windows Known Folders (Special Folders)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to copy the image of a form to the Clipboard using Bitmap API functions
Vertical Label control
Accessing Adobe Reader 7.0 main menu from VFP application
Storing screen shot of a form to bitmap file
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera

User rating: 9.5/10 (4 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
click to open
Before you begin:

This code sample has been tested with Logitech QuickCam Pro 4000 and with Dimera 350C USB Camera (an ancient camera from the year 2000) both operating under Windows XP.

Also I tested the code with Microsoft LifeCam VS-6000 on Vista Business 64-bit PC (the picture below).

No ActiveX controls are required, actually not much of programming is required either. Two API functions, capCreateCaptureWindow and SendMessage do practically all the job. The FoxPro form hosts a child window (the capture window) connected to existing capturing driver.

See also:
  • FoxTalk article: Using the Video Capture API in Visual FoxPro
  • //In [Project Properties - Linker - Input - Additional Dependencies] 
    //add Vfw32.lib
    #include "Vfw.h"
    HWND hCapture;
    VOID DriverDisconnect()
    BOOL IsCaptureConnected()
        CAPDRIVERCAPS psCaps ;
        ZeroMemory(&psCaps, sizeof(psCaps));
        SendMessage(hCapture, WM_CAP_DRIVER_GET_CAPS, 
            (WPARAM) sizeof(CAPDRIVERCAPS), (LPARAM) &psCaps);
        return psCaps.fCaptureInitialized;
    BOOL DriverConnect()
        SendMessage(hCapture, WM_CAP_DRIVER_CONNECT, NULL, NULL);
        return IsCaptureConnected();
    VOID StartPreview()
        SendMessage(hCapture, WM_CAP_SET_PREVIEWRATE, 15,0);
        SendMessage(hCapture, WM_CAP_SET_PREVIEW, 1,0);
        SendMessage(hCapture, WM_CAP_SET_OVERLAY, 1,0);
    VOID ReleaseCaptureWindow()
        if (hCapture != NULL)
    VOID ResizeCaptureWindow()
        BITMAPINFOHEADER bmpinfo;
        ZeroMemory(&bmpinfo, sizeof(bmpinfo));
        bmpinfo.biSize = sizeof(bmpinfo);
        SendMessage(hCapture, WM_CAP_GET_VIDEOFORMAT, 
            (WPARAM) sizeof(bmpinfo), (LPARAM) &bmpinfo);
        SetWindowPos(hCapture, 0,0,0, bmpinfo.biWidth, 
            bmpinfo.biHeight, SWP_SHOWWINDOW);
    VOID InitCaptureWindow(HWND hWnd)
       hCapture = capCreateCaptureWindow(NULL, 
           WS_CHILD|WS_VISIBLE, 0,0,1,1, hWnd, 1);
       if (hCapture == NULL) return;
       if (DriverConnect())
            SendMessage(hCapture, WM_CAP_SET_SCALE, 1,0);

    User rating: 9.5/10 (4 votes)
    Rate this code sample:
    • ~
    1560 bytes  
    Created: 2004-06-04 18:30:44  
    Modified: 2013-09-20 13:28:29  
    Visits in 7 days: 127  
    Listed functions:
    Printer friendly API declarations
    My comment:
    Apr.15, 2008: C++ version added
    May 27, 2007: all capWindow functionality moved to Custom control
    Oct.12, 2004: SaveToDib method captures and saves a single image as a device-independent bitmap (DIB).

    Windows Image Acquisition Automation Layer

    The Microsoft Windows Image Acquisition (WIA) Automation Layer 2.0 is a full-featured image manipulation component that provides end-to-end image processing capabilities. The WIA Automation Layer makes it easy to acquire images on digital cameras, scanners, or Web cameras, and to rotate, scale, and annotate your image files.

    Applications that use the WIA Automation LayerAPI require Windows XPService Pack 1 (SP1) or later. Earlier versions of Windows are not supported. You will need WIAAut.dll to use the WIA Automation Layer.

    * * *
    You may have several capture windows created and fed from different Video Sources. You can not feed two capture windows from same source.

    For example, now I have two digital cameras connected through USB -- Dimera 350C and Logitech QuickCam -- and one more video source, ATI TV Wonder Pro card that receives TV channels through coaxial cable.

    With slightly modified code I can create three capture windows, one for each video source. All three windows simultaneously display preview from their sources.

    * * *
    Window styles WS_SYSMENU, WS_CAPTION and WS_THICKFRAME applied to the capture window make it movable and resizable. WS_CHILD must be present in any combination of window styles.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian offers instant, free translations of text or web pages.
    User Contributed Notes:
    nestor hdz | 2005-05-16 11:48:49
    esta muy bueno, pero no sabras algo acerca de los lectores digitales ya que no he podido poner el que tenemos y es un U.are.U 4000sensor de digitalpersona

    mi correo es | 2005-07-22 17:58:31
    I get "Failed to connect to video input device." when I run this code in VFP 9.0.

    Clearly I need to be able to select the camera, but I fail to figure out how to select a camera at this time!

    Please help!

    Dennis Kean
    A.M. | 2005-07-22 18:05:34
    Dennis, I tried but found nothing in the API that could allow to select video source.

    When testing I had three sources connected to my computer -- two USB cameras and TV card. Every time the system tries to connect to the last device that was active.
    Alex | 2005-10-14 02:58:20

    I have not tested it, but think it might help.

    Have a look at


    A.M. | 2005-10-14 07:23:24
    Alex, I think I already tried those two and it did not work. Will give another try. | 2007-01-15 12:31:14
    I have the complete program that you sent in June 2005 and it operate. But upon executing this program by means of a command button of a form selected from a option of menu of user, it don't show the image of video.

    They could help me, thank you
    help | 2007-06-22 09:03:34
    Dear sir
    guide me to retrieve the saved image (.dib) and display in the form pls
    A.M. | 2007-06-25 21:41:58
    The SaveToDib method in the code above saves current frame in a DIB file.

    In VFP8/9 such DIB file can be directly assigned to the Picture property of VFP Image control, no format conversion is required. The control will display the image.

    As well such DIB image can be directly stored in General field of VFP table, for example:

    CREATE CURSOR csTmp (filename C(30), imagedata G)
    REPLACE filename WITH 'GRAB_3G17JDE3.DIB'

    Copyright 2001-2015 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.5.46), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (
    10.8 hrs.Example: 'Winsock: retrieving the host information corresponding to a network address'
     Example: 'How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory'
    10.81 hrs.Function: 'RegCreateKeyEx'
    10.86 hrs.Example: 'HOWTO: Use the Win32 API to Access File Dates and Times'
    6 day(s)Function: 'Shell_NotifyIcon'
    Function group: 'Shell Functions'
     Example: 'Terminating all running applications from a VFP program'
     Example: 'Using FrameRgn for displaying system colors'
     Example: 'Running a regular FoxPro form while main VFP window is minimized'
    Advertise here!