// TwainView.cpp : implementation of the CTwainView class // #include "stdafx.h" #include "Twain.h" #include "TwainDoc.h" #include "TwainView.h" #include "LEADRaster.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) // NOTE: the ClassWizard will add member initialization here //}}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_LEADRASTERVIEW, m_LEADRasterView); //}}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(); CTwainDoc * pDoc = (CTwainDoc *)GetDocument(); m_LEADRasterView.GetRaster().SetBitmap(pDoc->m_pLEADRaster->Bitmap); int xExt = (int)pDoc->m_pLEADRaster->BitmapWidth; int yExt = (int)pDoc->m_pLEADRaster->BitmapHeight; // Make the CLEADRasterView control to fit the bitmap and disable CLEADRasterView'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)); m_LEADRasterView.SetBackErase(FALSE); } ///////////////////////////////////////////////////////////////////////////// // 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_LEADRasterView.m_hWnd)) { m_LEADRasterView.SetBackErase(FALSE); m_LEADRasterView.MoveWindow(0, 0, cx, cy); } } void CTwainView::OnFileSaveAs() { CTwainApp * pApp = (CTwainApp *)AfxGetApp(); pApp->m_pRasterFileDlg->PutBitmap(m_LEADRasterView.GetRaster().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); pApp->m_pRasterFileDlg->PutBitmap(0); }