home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / Mfcdedoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-15  |  7.2 KB  |  299 lines

  1. // mfcdeDoc.cpp : implementation of the CMfcdemoDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mfcdemo.h"
  6. #include "colormer.h"
  7. #include "mfcdeDoc.h"
  8. #include "LeadDlg.h"
  9. #include "..\..\..\..\include\ltdlgocx.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. extern CMfcdemoApp theApp;
  18. extern short gnPage;
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMfcdemoDoc
  22.  
  23. IMPLEMENT_DYNCREATE(CMfcdemoDoc, CDocument)
  24.  
  25. BEGIN_MESSAGE_MAP(CMfcdemoDoc, CDocument)
  26.     //{{AFX_MSG_MAP(CMfcdemoDoc)
  27.     ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  28.     //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMfcdemoDoc construction/destruction
  33.  
  34. static const WCHAR BASED_CODE _szLicString[] =
  35.     L"LEADTOOLS OCX Copyright (c) 1998 LEAD Technologies, Inc.";
  36.  
  37. CMfcdemoDoc::CMfcdemoDoc()
  38. {
  39.     CRect   rcClient(0,0,1,1);
  40.     BSTR lpLic = SysAllocString(_szLicString);
  41.     m_Lead.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
  42.     m_Lead.ShowWindow(SW_HIDE);
  43.     /* m_Lead2 is used for supporting the floater bitmap in the view */
  44.     m_Lead2.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
  45.     m_Lead2.ShowWindow(SW_HIDE);
  46.     m_LeadUndo.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
  47.     m_LeadUndo.ShowWindow(SW_HIDE);
  48.     SysFreeString(lpLic);
  49.     m_nFormat = 5;
  50.     m_nBits = 0;
  51.     m_nQFactor = 2;
  52.     m_fMultipage = FALSE;
  53. }
  54.  
  55. CMfcdemoDoc::~CMfcdemoDoc()
  56. {
  57.     m_Lead.DestroyWindow();     // avoid warning messages at debug time
  58.     m_LeadUndo.DestroyWindow(); // avoid warning messages at debug time
  59. }
  60.  
  61. BOOL CMfcdemoDoc::OnNewDocument()
  62. {
  63.     if (!CDocument::OnNewDocument())
  64.         return FALSE;
  65.  
  66.     // handle the exceptions. If an exceptions would occur here, an
  67.     // invalid document would be created and the list of documents would be 
  68.     // corrupted causing big problems.
  69.     TRY
  70.     {
  71.         switch(theApp.m_nOpenMode)
  72.         {
  73.         case OPENMODE_COLORMERGE:
  74.             return OnOpenColorMerge();
  75.             break;
  76.         case OPENMODE_TWAIN:
  77.             return(OnOpenTwain());
  78.             break;
  79.         case OPENMODE_ISIS:
  80.             return(OnOpenIsis());
  81.             break;
  82.         case OPENMODE_BITMAP:
  83.             return(OnOpenBitmap());
  84.             break;
  85.         case OPENMODE_CAPTURE:
  86.             return(OnOpenCapture());
  87.             break;
  88.         case OPENMODE_PASTE:
  89.             return(OnOpenPaste());
  90.             break;
  91.         default:
  92.             break;
  93.         }
  94.     }
  95.     CATCH_ALL(e)
  96.     {
  97.         theApp.DisplayLEADError(ERROR_FAILURE);
  98.         return FALSE;
  99.     }
  100.     END_CATCH_ALL
  101.  
  102.     return FALSE;
  103. }
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CMfcdemoDoc serialization
  107.  
  108. void CMfcdemoDoc::Serialize(CArchive& ar)
  109. {
  110.     if (ar.IsStoring())
  111.     {
  112.         // TODO: add storing code here
  113.     }
  114.     else
  115.     {
  116.         // TODO: add loading code here
  117.     }
  118. }
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CMfcdemoDoc diagnostics
  122.  
  123. #ifdef _DEBUG
  124. void CMfcdemoDoc::AssertValid() const
  125. {
  126.     CDocument::AssertValid();
  127. }
  128.  
  129. void CMfcdemoDoc::Dump(CDumpContext& dc) const
  130. {
  131.     CDocument::Dump(dc);
  132. }
  133. #endif //_DEBUG
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CMfcdemoDoc commands
  137.  
  138. BOOL CMfcdemoDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  139. {
  140. //    COpenOptDlg dlg;
  141.     int nRet;
  142.  
  143.     if(lpszPathName)
  144.     {
  145.         nRet = m_Lead.Load(lpszPathName, 0, gnPage, 1);
  146.         gnPage = 1;
  147.         if(nRet)
  148.         {
  149.             theApp.DisplayLEADError(nRet);
  150.             return(FALSE);
  151.         }
  152.         return(TRUE);
  153.     }
  154.     return(FALSE);
  155. }
  156.  
  157. BOOL CMfcdemoDoc::OnSaveDocument(LPCTSTR lpszPathName) 
  158. {
  159.     int nRet;
  160.  
  161.     if(lpszPathName)
  162.     {
  163.         nRet = m_Lead.Save((LPSTR)lpszPathName, m_nFormat, m_nBits, m_nQFactor, m_fMultipage);
  164.         if(nRet)
  165.         {
  166.             theApp.DisplayLEADError(nRet);
  167.             return(FALSE);
  168.         }
  169.         SetModifiedFlag(FALSE);
  170.         return(TRUE);
  171.     }
  172.     return(FALSE);
  173. }
  174.  
  175. BOOL CMfcdemoDoc::OnOpenCapture() 
  176. {
  177.     theApp.m_pMainWnd->ShowWindow (SW_HIDE);
  178.     theApp.m_pMainWnd->UpdateWindow ();
  179.  
  180.     Sleep(1000);
  181.  
  182.     CClientDC cdc(theApp.m_pMainWnd->GetDesktopWindow());
  183.     m_Lead.Capture((OLE_HANDLE) cdc.m_hDC, 0.0f, 0.0f,
  184.          (float) cdc.GetDeviceCaps (HORZRES), (float) cdc.GetDeviceCaps (VERTRES));
  185.     theApp.m_pMainWnd->ShowWindow (SW_SHOW);
  186.     return(TRUE);        
  187. }
  188.  
  189. BOOL CMfcdemoDoc::OnOpenPaste() 
  190. {
  191.     m_Lead.Paste(0);
  192.     return(TRUE);        
  193. }
  194.  
  195. BOOL CMfcdemoDoc::OnOpenBitmap()
  196. {
  197.     m_Lead.SetBitmap(theApp.m_Bitmap);
  198.     return(TRUE);        
  199. }
  200.  
  201. BOOL CMfcdemoDoc::OnOpenTwain()
  202. {
  203.     int nRet;
  204.  
  205.     m_Lead.SetEnableMethodErrors(FALSE);
  206.     nRet = m_Lead.TwainAcquire((OLE_HANDLE) theApp.m_pMainWnd->m_hWnd);
  207.     m_Lead.SetEnableMethodErrors(TRUE);
  208.     
  209.     if( nRet )
  210.         theApp.DisplayLEADError(nRet);
  211.  
  212.     return(!nRet);
  213. }
  214.  
  215. BOOL CMfcdemoDoc::OnOpenIsis()
  216. {
  217.    CLeadIsis LTIsis;
  218.    RECT rcWin;
  219.    int nRet;
  220.    
  221.    ::SetRect(&rcWin, 0, 0, 1, 1);
  222.  
  223.    if(LTIsis.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  224.    {
  225.       LTIsis.SetEnableMethodErrors(FALSE);
  226.       nRet = LTIsis.ISISLoadDriver();
  227.       if(nRet == 0)
  228.       {
  229.          nRet == LTIsis.ISISAcquire((long)LTIsis.m_hWnd, ISIS_SHOWUI);
  230.          LTIsis.ISISUnloadDriver();
  231.       }
  232.  
  233.       if(nRet == 0)
  234.       {
  235.          m_Lead.SetBitmap(LTIsis.GetBitmap());
  236.          LTIsis.SetBitmap(0);
  237.       }
  238.       else if(nRet != ERROR_ISIS_CANCEL)
  239.       {
  240.          theApp.DisplayLEADError(nRet);
  241.          return(FALSE);
  242.       }
  243.    }
  244.    return(TRUE);
  245. }
  246.  
  247. BOOL CMfcdemoDoc::OnOpenColorMerge()
  248. {
  249.     CColorMergeDlg dlg(NULL,this);
  250.  
  251.     if(dlg.DoModal() == IDOK)
  252.     {
  253.         int i;
  254.         for(i = 0; i < 4; i++)
  255.             m_Lead.SetColorPlanes(i, ((CMfcdemoDoc*)dlg.m_pDocument[i])->m_Lead.GetBitmap());
  256.         m_Lead.ColorMerge(dlg.m_dwFlags);
  257.         for(i = 0; i < 4; i++)
  258.             m_Lead.SetColorPlanes(i, 0);
  259.         return(TRUE);
  260.     }
  261.     return(FALSE);
  262. }
  263.  
  264. void CMfcdemoDoc::OnFileSaveAs() 
  265. {
  266.    CLeadDlg LTCommDlg;
  267.    RECT rcWin;
  268.    BOOL bContinue=FALSE;
  269.    CString sFileName;
  270.    int nRet;
  271.    
  272.    ::SetRect(&rcWin, 0, 0, 1, 1);
  273.  
  274.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  275.    {
  276.       LTCommDlg.SetEnableMethodErrors(FALSE);
  277.       LTCommDlg.SetFileDlgFlags(0);
  278.       LTCommDlg.SetSaveFormatFlags(DLG_FS_ALL);
  279.       LTCommDlg.SetDialogTitle("Save File");
  280.       LTCommDlg.SetUIFlags( DLG_FS_95STYLE | DLG_FS_MULTIPAGE | DLG_FS_QFACTOR );
  281.       nRet = LTCommDlg.FileSave((long)theApp.m_pMainWnd->m_hWnd);
  282.       if(nRet == 0)
  283.          bContinue = TRUE;
  284.    }
  285.    if(bContinue)
  286.    {
  287.       sFileName = LTCommDlg.GetFileName();
  288.       m_nFormat = LTCommDlg.GetSaveFormat();
  289.       m_nBits = LTCommDlg.GetSaveBitsPerPixel();
  290.       m_nQFactor = LTCommDlg.GetSaveQFactor();
  291.       m_fMultipage = LTCommDlg.GetSaveMulti();
  292.       m_Lead.SetSaveInterlaced(LTCommDlg.GetSaveInterlaced());
  293.       OnSaveDocument((LPCTSTR)sFileName);
  294.    }
  295.    else if(nRet != ERROR_DLG_CANCELED)
  296.       theApp.DisplayLEADError(nRet);
  297.    return;
  298. }
  299.