// TwainView.cpp : implementation of the CTwainView class // #include "stdafx.h" #include "Twain.h" #include "TwainDoc.h" #include "TwainView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTwainView IMPLEMENT_DYNCREATE(CTwainView, CFormView) BEGIN_MESSAGE_MAP(CTwainView, CFormView) //{{AFX_MSG_MAP(CTwainView) ON_WM_SIZE() ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTwainView construction/destruction CTwainView::CTwainView() : CFormView(CTwainView::IDD) { //{{AFX_DATA_INIT(CTwainView) //}}AFX_DATA_INIT // TODO: add construction code here } CTwainView::~CTwainView() { } void CTwainView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTwainView) DDX_Control(pDX, IDC_LEADCTRL, m_LEADCtrl); //}}AFX_DATA_MAP } BOOL CTwainView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } void CTwainView::OnInitialUpdate() { CFormView::OnInitialUpdate(); int xExt = (int)m_LEADCtrl.GetBitmapWidth(); int yExt = (int)m_LEADCtrl.GetBitmapHeight(); // Make the CLead control to fit the bitmap and disable CLead's scrolling // Make the form scroll if the window becomes smaller than the bitmap SetScrollSizes(MM_TEXT,CSize(xExt,yExt)); // Make the window fit the image GetParentFrame()->RecalcLayout(); ResizeParentToFit(); // now disable the scroll bars SetScrollSizes(MM_TEXT,CSize(1,1)); CTwainDoc* pDoc = GetDocument(); } ///////////////////////////////////////////////////////////////////////////// // CTwainView printing BOOL CTwainView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CTwainView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CTwainView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CTwainView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) { // TODO: add customized printing code here } ///////////////////////////////////////////////////////////////////////////// // CTwainView diagnostics #ifdef _DEBUG void CTwainView::AssertValid() const { CFormView::AssertValid(); } void CTwainView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CTwainDoc* CTwainView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTwainDoc))); return (CTwainDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTwainView message handlers void CTwainView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); if (IsWindow(m_LEADCtrl.m_hWnd)) { m_LEADCtrl.SetBackErase(FALSE); m_LEADCtrl.MoveWindow(0, 0, cx, cy); } } void CTwainView::OnFileSaveAs() { CTwainApp * pApp = (CTwainApp *)AfxGetApp(); pApp->m_pRasterFileDlg->PutBitmap(m_LEADCtrl.GetBitmap()); pApp->m_pRasterFileDlg->PutEnableMethodErrors(FALSE); pApp->m_pRasterFileDlg->PutFileDlgFlags(0); pApp->m_pRasterFileDlg->PutUIFlags(SAVE_AUTOPROCESS | SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | SAVE_SHOW_FILEOPTIONS_QFACTOR | SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS); pApp->m_pRasterFileDlg->PutDialogTitle("Save File"); pApp->m_pRasterFileDlg->ShowSaveDlg((long)m_hWnd); } void CTwainView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CTwainDoc* pDoc = GetDocument(); m_LEADCtrl.SetAutoRepaint(FALSE); m_LEADCtrl.SetBitmap(GetDocLead()->GetBitmap()); m_LEADCtrl.SetDstRect(m_LEADCtrl.GetDstLeft(), m_LEADCtrl.GetDstTop(), m_LEADCtrl.GetBitmapWidth(), m_LEADCtrl.GetBitmapHeight()); m_LEADCtrl.SetDstClipRect(m_LEADCtrl.GetDstLeft(), m_LEADCtrl.GetDstTop(), m_LEADCtrl.GetDstWidth(), m_LEADCtrl.GetDstHeight()); m_LEADCtrl.SetAutoRepaint(TRUE); } CLead* CTwainView::GetDocLead() { CTwainDoc* pDoc = GetDocument(); return (&pDoc->m_LEADCtrl); }