home *** CD-ROM | disk | FTP | other *** search
- // mfcdeDoc.cpp : implementation of the CMfcdemoDoc class
- //
-
- #include "stdafx.h"
- #include "mfcdemo.h"
- #include "colormer.h"
- #include "mfcdeDoc.h"
- #include "LeadDlg.h"
- #include "..\..\..\..\include\ltdlgocx.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- extern CMfcdemoApp theApp;
- extern short gnPage;
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc
-
- IMPLEMENT_DYNCREATE(CMfcdemoDoc, CDocument)
-
- BEGIN_MESSAGE_MAP(CMfcdemoDoc, CDocument)
- //{{AFX_MSG_MAP(CMfcdemoDoc)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc construction/destruction
-
- static const WCHAR BASED_CODE _szLicString[] =
- L"LEADTOOLS OCX Copyright (c) 1998 LEAD Technologies, Inc.";
-
- CMfcdemoDoc::CMfcdemoDoc()
- {
- CRect rcClient(0,0,1,1);
- BSTR lpLic = SysAllocString(_szLicString);
- m_Lead.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
- m_Lead.ShowWindow(SW_HIDE);
- /* m_Lead2 is used for supporting the floater bitmap in the view */
- m_Lead2.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
- m_Lead2.ShowWindow(SW_HIDE);
- m_LeadUndo.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
- m_LeadUndo.ShowWindow(SW_HIDE);
- SysFreeString(lpLic);
- m_nFormat = 5;
- m_nBits = 0;
- m_nQFactor = 2;
- m_fMultipage = FALSE;
- }
-
- CMfcdemoDoc::~CMfcdemoDoc()
- {
- m_Lead.DestroyWindow(); // avoid warning messages at debug time
- m_LeadUndo.DestroyWindow(); // avoid warning messages at debug time
- }
-
- BOOL CMfcdemoDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
-
- // handle the exceptions. If an exceptions would occur here, an
- // invalid document would be created and the list of documents would be
- // corrupted causing big problems.
- TRY
- {
- switch(theApp.m_nOpenMode)
- {
- case OPENMODE_COLORMERGE:
- return OnOpenColorMerge();
- break;
- case OPENMODE_TWAIN:
- return(OnOpenTwain());
- break;
- case OPENMODE_ISIS:
- return(OnOpenIsis());
- break;
- case OPENMODE_BITMAP:
- return(OnOpenBitmap());
- break;
- case OPENMODE_CAPTURE:
- return(OnOpenCapture());
- break;
- case OPENMODE_PASTE:
- return(OnOpenPaste());
- break;
- default:
- break;
- }
- }
- CATCH_ALL(e)
- {
- theApp.DisplayLEADError(ERROR_FAILURE);
- return FALSE;
- }
- END_CATCH_ALL
-
- return FALSE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc serialization
-
- void CMfcdemoDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc diagnostics
-
- #ifdef _DEBUG
- void CMfcdemoDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CMfcdemoDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc commands
-
- BOOL CMfcdemoDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- // COpenOptDlg dlg;
- int nRet;
-
- if(lpszPathName)
- {
- nRet = m_Lead.Load(lpszPathName, 0, gnPage, 1);
- gnPage = 1;
- if(nRet)
- {
- theApp.DisplayLEADError(nRet);
- return(FALSE);
- }
- return(TRUE);
- }
- return(FALSE);
- }
-
- BOOL CMfcdemoDoc::OnSaveDocument(LPCTSTR lpszPathName)
- {
- int nRet;
-
- if(lpszPathName)
- {
- nRet = m_Lead.Save((LPSTR)lpszPathName, m_nFormat, m_nBits, m_nQFactor, m_fMultipage);
- if(nRet)
- {
- theApp.DisplayLEADError(nRet);
- return(FALSE);
- }
- SetModifiedFlag(FALSE);
- return(TRUE);
- }
- return(FALSE);
- }
-
- BOOL CMfcdemoDoc::OnOpenCapture()
- {
- theApp.m_pMainWnd->ShowWindow (SW_HIDE);
- theApp.m_pMainWnd->UpdateWindow ();
-
- Sleep(1000);
-
- CClientDC cdc(theApp.m_pMainWnd->GetDesktopWindow());
- m_Lead.Capture((OLE_HANDLE) cdc.m_hDC, 0.0f, 0.0f,
- (float) cdc.GetDeviceCaps (HORZRES), (float) cdc.GetDeviceCaps (VERTRES));
- theApp.m_pMainWnd->ShowWindow (SW_SHOW);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenPaste()
- {
- m_Lead.Paste(0);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenBitmap()
- {
- m_Lead.SetBitmap(theApp.m_Bitmap);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenTwain()
- {
- int nRet;
-
- m_Lead.SetEnableMethodErrors(FALSE);
- nRet = m_Lead.TwainAcquire((OLE_HANDLE) theApp.m_pMainWnd->m_hWnd);
- m_Lead.SetEnableMethodErrors(TRUE);
-
- if( nRet )
- theApp.DisplayLEADError(nRet);
-
- return(!nRet);
- }
-
- BOOL CMfcdemoDoc::OnOpenIsis()
- {
- CLeadIsis LTIsis;
- RECT rcWin;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTIsis.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTIsis.SetEnableMethodErrors(FALSE);
- nRet = LTIsis.ISISLoadDriver();
- if(nRet == 0)
- {
- nRet == LTIsis.ISISAcquire((long)LTIsis.m_hWnd, ISIS_SHOWUI);
- LTIsis.ISISUnloadDriver();
- }
-
- if(nRet == 0)
- {
- m_Lead.SetBitmap(LTIsis.GetBitmap());
- LTIsis.SetBitmap(0);
- }
- else if(nRet != ERROR_ISIS_CANCEL)
- {
- theApp.DisplayLEADError(nRet);
- return(FALSE);
- }
- }
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenColorMerge()
- {
- CColorMergeDlg dlg(NULL,this);
-
- if(dlg.DoModal() == IDOK)
- {
- int i;
- for(i = 0; i < 4; i++)
- m_Lead.SetColorPlanes(i, ((CMfcdemoDoc*)dlg.m_pDocument[i])->m_Lead.GetBitmap());
- m_Lead.ColorMerge(dlg.m_dwFlags);
- for(i = 0; i < 4; i++)
- m_Lead.SetColorPlanes(i, 0);
- return(TRUE);
- }
- return(FALSE);
- }
-
- void CMfcdemoDoc::OnFileSaveAs()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- CString sFileName;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- LTCommDlg.SetFileDlgFlags(0);
- LTCommDlg.SetSaveFormatFlags(DLG_FS_ALL);
- LTCommDlg.SetDialogTitle("Save File");
- LTCommDlg.SetUIFlags( DLG_FS_95STYLE | DLG_FS_MULTIPAGE | DLG_FS_QFACTOR );
- nRet = LTCommDlg.FileSave((long)theApp.m_pMainWnd->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- }
- if(bContinue)
- {
- sFileName = LTCommDlg.GetFileName();
- m_nFormat = LTCommDlg.GetSaveFormat();
- m_nBits = LTCommDlg.GetSaveBitsPerPixel();
- m_nQFactor = LTCommDlg.GetSaveQFactor();
- m_fMultipage = LTCommDlg.GetSaveMulti();
- m_Lead.SetSaveInterlaced(LTCommDlg.GetSaveInterlaced());
- OnSaveDocument((LPCTSTR)sFileName);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- return;
- }
-