Painting Pages and Zones

Take the following steps to add code to the existing project that will let you recognize pages:

1.

Start with the program you created in Working with Pages.

2.

Add the following command buttons to the main window and set the ID and Caption properties as follows:

 

ID

Caption

 

IDC_DRAW_ZONES

Draw Zones

 

IDC_DRAWPAGE

Draw Page

3.

Edit the OCRTutorDlg.h file and change the definition of COCRTutorDlg : CDialog by inserting the following line after DECLARE_MESSAGE_MAP:

   BOOL m_bDrawZones;
   BOOL m_bDrawPage;

4.

Edit the OCRTutorDlg.cpp file and add the following to the OnInitDialog procedure as follows:

   m_bDrawZones FALSE;
   m_bDrawPage TRUE;

5.

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 COCRTutorDlg.

 

c.

In the Object IDs list box, select IDC_DRAW_ZONES.

 

d.

In the Messages list box, select BN_CLICKED

 

e.

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

 

f.

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

   m_bDrawZones = !m_bDrawZones;

6.

Edit the OnAddpage procedure, add the following lines after "AddPage()…":

   m_bDrawPage = FALSE;
   m_pRasterDoc->ActivePageIndex = 0;
   m_bDrawPage = TRUE;

7.

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 COCRTutorDlg.

 

c.

In the Object IDs list box, select IDC_DRAWPAGE.

 

d.

In the Messages list box, select BN_CLICKED

 

e.

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

 

f.

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

   if (m_bDrawPage) 
   {
      CClientDC * pDc = new CClientDC(this); 
      m_pRasterDoc->EnableShowZones = m_bDrawZones; 
      m_pRasterDoc->DrawPersistence = FALSE; 
      m_pRasterDoc->DrawPage (NULL, (long)pDc->m_hDC, 0); 
   }

8.

Build OCRTutor.exe.

9.

Run OCRTutor.exe.