IC Imaging Control C++

First Steps VC.NET

First Steps VC.NET

Select a Video Capture Device and display a Live Image

Open the class view in the project explorer and right click on the "CFirstStepView" class. Select "Properties" from the context menu and click on the "Overrides" button. Now add the OnInitialUpdate method.

image

To select a video capture device, use the built-in device selection dialog. This is done in the OnInitialUpdate method of the CFirstStepView class. 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.") );
    }
}

Before the application terminates, the live video should be stopped and the device should be closed. To do so, add the OnCloseDocument method. Open the class view in the project explorer and right click on the "CFirstStepDoc" class. Select "Properties" from the context menu and click on the "Overrides" button. Now add the OnCloseDocument method.

image

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