Getting started in Visual C++
Top  Previous  Next

This chapter shows you how to get started with ActiveGige 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 MyActiveGige and click OK . When MFC AppWizard appears, select Dialog based radio button and click Finish . The project will be created, and the program dialog MyActiveGige will be displayed for editing.

VC++ 2005-2015

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 MyActiveGige 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 MyActiveGige 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 ActiveGige class and press OK .
A white rectangle 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_ACTIVEGIGE1 and then click Add Variable. Confirm generating the new CActiveGige class. When the Add Member Variable dialog appears, enter the name for the ActiveGige object, for instance m_ActiveGige . Click OK to close the Wizard.

VC++ 2005-2015

Right click on the ActiveGige 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 ActiveGige object, for instance m_ActiveGige , and click finish. The Wizard will generate a wrapper class for ActiveGige control and add a corresponding member variable to the main dialog class.

Selecting the Camera

Right click on the ActiveGige 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 ActiveGige Class Properties tab dialog. Click the Source tab. The Camera list box will contain the names of GigE Vision™ cameras connected to your system. Select the one you intend to use.

clip0059


Selecting the Video Format

Switch to the Format tab. Click the arrow next to the Format box. The list box will display all the pixel formats available for the chosen camera. Select the one you intend to use. Then select the desired image size in the Width and Height boxes.

clip0060


Adjusting the Analog settings

Switch to the Analog tab. Using the slider controls and list boxes adjust the exposure, gain, black level and white balance 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 CMyActiveGigeDlg::OnButton1()
{
   // TODO: Add your control notification handler code here

   m_ActiveGige.SetAcquire(TRUE);   
}

VC++ 2005, 2008, 2010

void
CMyActiveGigeDlg::OnBnClickedButton1()
{
   // TODO: Add your control notification handler code here
   m_ActiveGige.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 ActiveGige 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 OnMouseMoveActivegige1 will be added to the source code. Add the following lines to the body of the function:

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

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

Running the application

Close the main application form. From the Build menu of the development environment select Execute MyActiveGige.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!

Note - make sure to close the form containing ActiveGige control before running your application, or otherwise the IDE will maintain the exclusive control over the camera and will not allow your application to display the video.