The Automation and the Container

Start with the project you created in Implementing the Paint Automation Initializing, Creating and Freeing.

1.

Add the following declaration to the WndProc function:

static pCONTAINERHANDLE pContainer ;

2.

Add the following code to the WndProc function after the ReleaseDC statement in the ID_FILE_OPEN of the WM_COMMAND message:

 

{//AUTOMATION CONTAINER STUFF
   CONTAINERPAINTDATA PaintData ; 


   {//REMOVE THE OLD CONTAINER (IF ANY)     
      if ( SUCCESS == L_ContainerIsValid ( pContainer ) ) 
      {
            L_AutRemoveContainer ( pAutomation, pContainer ) ;            L_ContainerFree ( pContainer ) ; 
      }
   
   }//REMOVE THE OLD CONTAINER (IF ANY) 
           
   PaintData.pBitmap             = &hBitmap ; 
   PaintData.hRestrictionPalette = hPalette ; 
           
   L_ContainerInit ( &pContainer ) ; 
               
   L_ContainerCreate ( pContainer, hWnd ) ; 
      
   L_AutAddContainer ( pAutomation, pContainer, &PaintData ) ; 
            
}//AUTOMATION CONTAINER STUFF

3.

Add the following code before the " L_AutFree " function call in the WndProc function in the WM_DESTROY message:

 

if ( SUCCESS == L_ContainerIsValid ( pContainer ) ) 
{
   L_AutRemoveContainer ( pAutomation, pContainer ) ; 

   L_ContainerFree ( pContainer ) ; 
}

 

4.

Add the following declaration to the WndProc function:

VECTORPOINT vptScalarNum, vptScalarDen ;

5.

Add the following lines before the OnSize function call in the "case WM_SIZE:" in the WndProc function:

 

if ( SUCCESS == L_ContainerIsValid ( pContainer ) ) 
{
   L_ContainerGetScalar ( pContainer, &vptScalarNum, &vptScalarDen ) ; 

   nScalarNum = ( L_INT ) vptScalarNum.x ; 
   nScalarDen = ( L_INT ) vptScalarDen.x ; 
}
        

6.

Add the following container function call after the OnSize function call in the "case WM_SIZE:" in the WndProc function:

L_ContainerSetOffset ( pContainer, - rcView.left, - rcView.top, 0 ) ; 

7.

Add the following container function call after the OnHScroll function call in the "case WM_HSCROLL:" in the WndProc function:

L_ContainerSetOffset ( pContainer, - rcView.left, - rcView.top, 0 ) ;

8.

Add the following container function call after the OnVScroll function call in the "case WM_VSCROLL:" in the WndProc function:

L_ContainerSetOffset ( pContainer, - rcView.left, - rcView.top, 0 ) ;

9.

Compile and run the project by selecting Build->Execute tutorial.exe from the menu.