OptimizeDir example for C++ 5.0 and later

void CRasterOptimizerSink::OnOptimizeDir ()
{
   static int nFileCount = 1; 
   CString strMsg; 

   switch(theApp.m_pImageOptmizer->GetDirectoryInfo ()->GetStatusCode ())
   {
   case OPTIMIZE_SUCCESS : 
      MessageBox(0,TEXT("Operation Successfully Done"),0,0); 
      break; 
   
   case OPTIMIZE_DIR_PRE_OPTIMIZING_IMAGE: 
      MessageBox (0, TEXT("Operation Successfully Done"),TEXT("Note"),0); 
      break; 
    
   case OPTIMIZE_DIR_OPTIMIZING_IMAGE: 
      {
         long nFilePercent   = theApp.m_pImageOptmizer->GetDirectoryInfo ()->FilePercent
         CString OriginalFileName    = theApp.m_pImageOptmizer->GetDirectoryInfo ()->OriginalFileName.copy();
         CString OptimizedFileName  = theApp.m_pImageOptmizer->GetDirectoryInfo ()->OptimizedFileName.copy();
         long nTotalFolderFilesCount =theApp.m_pImageOptmizer->GetDirectoryInfo ()->TotalFolderFilesCount
         long nPercent = theApp.m_pImageOptmizer->GetDirectoryInfo ()->GetOptimizeOptions()->GetPercent();
         long nTotalPercent = theApp.m_pImageOptmizer->GetDirectoryInfo()->TotalPercent
         strMsg.Format(TEXT("%d %% of optimizing %s to %s \nFiles %d of %d  Total Prcent = %d Percent = %d"), 
                        nFilePercent, 
                        OriginalFileName, 
                        OptimizedFileName, 
                        nFileCount, 
                        nTotalFolderFilesCount, 
                        nTotalPercent, 
                        nPercent); 
         MessageBox(NULL, strMsg, TEXT("Optimizing"), MB_OK); 

         // if nFilePercent = 100 increment the counter by 1
         if((nFilePercent == 100) && ((nFileCount + 1) <= nTotalFolderFilesCount)) 
            nFileCount++;

      }
      break; 

   default: 
      {
         CString OriginalFileName    = theApp.m_pImageOptmizer->GetDirectoryInfo ()->OriginalFileName.copy();
         long nFilePercent = theApp.m_pImageOptmizer->GetDirectoryInfo ()->FilePercent
            /* report error to user */
            /* Give the user the ability to skip the current image only or cancel the whole operation*/
            strMsg.Format(TEXT("Error: %d - Optimizing Image!\n%s\nPress OK to skip this file and optimize the next one!"), 
               nFilePercent, OriginalFileName); 
            if(MessageBox(NULL, strMsg, TEXT("Error"), MB_OKCANCEL|MB_ICONERROR) == IDOK) 
               theApp.m_pImageOptmizer->OptimizingError = ERROR_OPT_SKIPIMAGE; 
            else
               theApp.m_pImageOptmizer->OptimizingError = ERROR_OPT_ABORT; 
      }
      break; 
   }
}

void COptimizerDlg::OnOptimizeDir()
{
   theApp.m_pImageOptmizer->EnableMethodErrors = FALSE; 
   int nRet=theApp.m_pImageOptmizer->OptimizeDir(TEXT("c:\\Org"), TEXT("C:\\Opt"), theApp.m_pImageOptmizer->DefaultOptions(), TEXT("*.jpg;*.bmp;*.tmp"), true, true); 
}