Getting started in Visual C++
Top  Previous  Next

This chapter shows you how to get started with ActiveDcam control in Visual C++. With just a few mouse clicks and a few lines of code, you will be able to display a live video image in your C++ program and report a value of a pixel pointed by a mouse cursor in real time.
.
Creating the Project

VC++ 6.0

In the development environment select the New command from the file menu, and then select Projects/MFC AppWizard.exe . In the Project name field on the right type the name of your application, for instance MyActiveDcam and click OK . When MFC AppWizard appears, select Dialog based radio button and click Finish . The project will be created, and the program dialog MyActiveDcam will be displayed for editing.

VC++ 2005, 2008, 2010, 2012

In the .NET development environment select New -> Project. The New Project Dialog box will appear. Select Visual C++ projects on the left and MFC Application on the right. In the Name filed below type the name of your application, for instance MyActiveDcam and click OK . When MFC Application Wizard appears, click Application Type , select Dialog based radio button and click Finish . The project will be created, and the program dialog MyActiveDcam will be displayed for editing.

Creating the Control

Right click in the dialog and select Insert ActiveX control from a shortcut menu. From the list of controls select ActiveDcam class and press OK .
A white rectangle with the text "ActiveDcam Control" will appear on the dialog.

Generating the class for the Control

VC++ 6.0

Right click in the dialog and select Class Wizard from the shortcut menu. When MFC Class Wizard appears, click the Member Variables tab. In the Control ID window click IDC_ACTIVEDCAM1 and then click Add Variable. Confirm generating the new CActiveDcam class. When the Add Member Variable dialog appears, enter the name for the ActiveDcam object, for instance m_ActiveDcam . Click OK to close the Wizard.

VC++ 2005, 2008, 2010, 2012

Right click on the ActiveDcam control in the program dialog and select Add Variable from the shortcut menu. Add Member Variable Wizard will appear. In the Variable name field enter the name for the ActiveDcam object, for instance m_ActiveDcam , and click finish. The Wizard will generate a wrapper class for ActiveDcam control and add a corresponding member variable to the main dialog class.

Selecting the Camera

Right click on the ActiveDcam control in the program dialog and select Properties from the shortcut menu. (In .NET select Property pages from the View menu). This will display the ActiveDcam Class Properties tab dialog. Click the Source tab. The Camera list box will contain the names of the DCAM cameras connected to your system. Select the one you intend to use.

clip0059


Selecting the Video Mode and Frame Rate

Switch to the Format tab. Click the arrow next to the Mode box. The list box will display all the video modes available for the chosen camera. Select the one you intend to use. Then select the desired frame rate from the Rate list box.

clip0060


Adjusting the Exposure settings

Switch to the Exposure tab. Using the slider controls adjust the Shutter, Gain and Iris settings. Note that the availability of the controls depends on the selected camera.

clip0061


Modifying the Control's appearance

Switch to the Source tab. Select 3D look and Scroll bars check boxes:

clip0062

Adding the Start button

In the Controls toolbox click on the Button icon and then draw a rectangular area on the program dialog. A button "Button1" will appear. Right click on the button and select Properties from the shortcut menu. In the Caption field type "Start" and double click on the button. The Add Member Function dialog box will appear. After clicking OK the source code window will be displayed with the new member function OnButton1 added. Insert one line to the function body:

VC++ 6.0

void CMyActiveDcamDlg::OnButton1()
{
   // TODO: Add your control notification handler code here

   m_ActiveDcam.SetAcquire(TRUE);   
}

VC++ 2005, 2008, 2010, 2012

void
CMyActiveDcamDlg::OnBnClickedButton1()
{
   // TODO: Add your control notification handler code here
   m_ActiveDcam.put_Acquire(TRUE);
}

This will activate continuous acquisition when the button is clicked.

Adding text boxes

In the Controls toolbox click on the Edit Box icon and then draw a small rectangular area on the program dialog. Repeat this two more times. Your final design of the program dialog will be similar to this:

clip0063


Adding the MouseMove event

Right click on the ActiveDcam control in the program dialog and select Events. . from the shortcut menu. Highlight the MouseMove event and click Add and Edit. The new event handler OnMouseMoveActivedcam1 will be added to the source code. Add the following lines to the body of the function:

void
CMyActiveDcamDlg::OnMouseMoveActivedcam1(short x, short y)
{
   // TODO: Add your control notification handler code here

   SetDlgItemInt(IDC_EDIT1,x);
   SetDlgItemInt(IDC_EDIT2,y);
   SetDlgItemInt(IDC_EDIT3,m_ActiveDcam.GetPixel(x,y));
}

Running the application

From the Build menu of the development environment select Execute MyActiveDcam.exe. This will build and run the application. The application dialog will appear on the screen with a black image window and empty text boxes. Click the Start button to activate the continuous video acquisition and move the mouse cursor over the image window. You are now able to watch and scroll the live image and analyze pixel coordinates and values - all in real time!