IC Imaging Control C++

First Steps VC6

First Steps VC6

Select a Video Capture Device and display a Live Image

Select "Class Wizard..." in the "View" menu to open the class wizard. Select "CFirstStepView" in the "Class name" field. Then select "OnInitialUpdate" in the "Messages" list and press the "Add function" button.

image

In order to select a video capture device, use the built-in device selection dialog. This is done in the "OnInitialUpdate" method of the CFirstStepView class, generated by the class wizard. Change its code as follows:

void CFirstStepView::OnInitialUpdate() 
{
    CView::OnInitialUpdate();
    
    // TODO: Add your specialized code here and/or call the base class
 
    // Get the grabber from the document class.
    DShowLib::Grabber* pGrabber = GetDocument()->m_pGrabber;
    
    // Show the device page.
    pGrabber->showDevicePage();
 
    // Check if there is a valid device.
    if( pGrabber->isDevValid() )
    {
        // Set the window that should display the live video.
        pGrabber->setHWND( m_hWnd );    
        // Start the live video.
        pGrabber->startLive();    
    }
    else
    {
        AfxMessageBox( TEXT("No device was selected.") );
    }
}

The OnCloseDocument method closes the device when the program terminates. To add the OnCloseDocument method, open the class wizard and select "CFirstStepDoc" in the "Class name" field. Select "OnCloseDocument" in the "Messages" list and press the "Add function" button. Insert the following code into the OnCloseDocument method:

void CFirstStepDoc::OnCloseDocument() 
{
    // TODO: Add your specialized code here and/or call the base class
 
    // Stop live mode.
    m_pGrabber->stopLive();
   
    // this call will also succeed if no device is open
    m_pGrabber->closeDev();
    
    CDocument::OnCloseDocument();
}

Now compile and run the project. After a device has been selected in the device selection dialog, a live image will be displayed.

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us