Save And Restore Video Capture Device Properties This short source code snippet illustrates how to save and restore video capture device properties with IC Imaging Control.
Language: | Visual C++
Version: | 3.3
Author: | IC Imaging Control Support Department
Requirements: |
Software: | IC Imaging Control 3.3, Visual Studio™ 2010
Hardware: | Camera, converter or grabber with WDM Stream Class drivers.
Download C++ sample | Save And Restore Device - VC71

The sample application's window looks as follows:

First of all, an MFC - Dialog based application is created. Additionally, there are four buttons for opening the video capture device, show the IC Imaging Control's built-in property dialog and save and load the device from an .xml file.

An instance of the Grabber class must be created as member of the dialog class.

    DShowLib::Grabber        m_cGrabber; // The instance of the Grabber class.

In the "Device" button event handler a video capture device is to be selected. First of all, it must be checked, whether the current Grabber object contains already a running video capture device, before IC Imaging Control's built-in "Device Selection" dialog can be called. The "Device Settings" dialog is shown with a call to Grabber::showDevicePage(). After the "Device Settings" dialog has been left, it is checked whehter a valid video capture device has been selected. If the video capture device in the Grabber object is valid, then the image data stream is started with a call to Grabber::startLive().

    void CSaveRestorePropertiesDlg::OnBnClickedDevice()
    {
        if(m_cGrabber.isDevValid() && m_cGrabber.isLive())
        {
            m_cGrabber.stopLive();
        }

        m_cGrabber.showDevicePage(this->m_hWnd);

        if(m_cGrabber.isDevValid())
        {
            m_cGrabber.startLive();
        }
    }

The "Properties" button event handler shows the build-in dialog for device proiperties with a call to Grabber::showVCDPropertyPage():

    void CSaveRestorePropertiesDlg::OnBnClickedProperties()
    {
        if( m_cGrabber.isDevValid())
        {
            m_cGrabber.showVCDPropertyPage(this->m_hWnd);
        }
    }

The method Grabber::saveDeviceStateToFile() saves the current settings and properties of a video capture deivce to an XML file:

    void CSaveRestorePropertiesDlg::OnBnClickedSave()
    {
        if( m_cGrabber.isDevValid())
        {
            m_cGrabber.saveDeviceStateToFile("device.xml");
        }
    }

The method Grabber::loadDeviceStateFromFile restores a previously saved video capture device and its properties from an XML file. As for the device selection dialog, it is necessary to stop a probably running live video before a new video capture device can be opened. If a valid video capture device was loaded, the image data stream will be started using Grabber.startLive():

    void CSaveRestorePropertiesDlg::OnBnClickedRestore()
    {
        if(m_cGrabber.isDevValid() && m_cGrabber.isLive())
        {
            m_cGrabber.stopLive();
        }

        if( m_cGrabber.loadDeviceStateFromFile( "device.xml"))
        {
            if( m_cGrabber.isDevValid())
                m_cGrabber.startLive();
        }
    }