Capturing a Selected Object (Visual C++ 5 and later)

Take the following steps to add some code that will let you capture a selected object.

1.

Start with the project you created in Capturing an Active Window.

2.

Add a command button and set the ID and Caption properties as follows:

 

ID

Caption

 

IDC_CAPOBJ

Capture Object

 

3.

Press Ctrl-W to go to the MFC Class Wizard; then do the following:

 

a.

Click the Message Maps tab.

 

b.

In the Class Name combo box, select CScrCapDlg.

 

c.

In the Object IDs list box, select IDC_CAPOBJ.

 

d.

In the Messages list box, select BN_CLICKED.

 

e.

Click the Add function button. Choose OK for the default function name (OnCapobj).

 

f.

Click the Edit Code button and code the OnCapobj procedure as follows:

void CScrCapDlg::OnCapobj() 
{
   /*display the capture selected object dialog*/
   m_pLEADRasterScr->CaptureObjectOptionDlg ((long)this->m_hWnd);
   /* capture the selected object */
   m_pLEADRasterScr->CaptureSelectedObject ();
   /* assign the screen control bitmap to the Main control bitmap */
   m_LEADRasterView1.GetRaster().SetBitmap(m_pLEADRasterScr->GetBitmap ());
   /* reset the object options */
   m_pLEADRasterScr->ResetObjectOptions ();
}

4.

On the main menu, select Build> Build ScrCap.exe to build the project.

5.

On the main menu, select Build> Execute ScrCap.exe to run the project. Click the Capture Select command button. Set the options. Click OK. Select the window containing the object you want to capture. Press F11. Move the cursor over the object you want to capture and click the left mouse button.