// PrntView.cpp : implementation of the CPrintingView class // #include "stdafx.h" #include "Prnt.h" #include "PrntDoc.h" #include "PrntView.h" #include "ZoomDlg.h" #include "MainFrm.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPrintingView IMPLEMENT_DYNCREATE(CPrintingView, CScrollView) BEGIN_MESSAGE_MAP(CPrintingView, CScrollView) //{{AFX_MSG_MAP(CPrintingView) ON_COMMAND(ID_FILE_PRINT, OnFilePrint) ON_COMMAND(ID_ZOOM_OUT, OnZoomOut) ON_COMMAND(ID_ZOOM_IN, OnZoomIn) ON_COMMAND(ID_NORMAL, OnNormal) ON_COMMAND(ID_VIEW_ZOOMING, OnViewZooming) ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview) ON_COMMAND(ID_CLOSE_PREVIEW, OnClosePreview) ON_WM_CREATE() ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, OnUpdateFilePrintPreview) ON_COMMAND(ID_ONE_PAGE, OnOnePage) ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMING, OnUpdateViewZooming) ON_UPDATE_COMMAND_UI(ID_ONE_PAGE, OnUpdateOnePage) ON_COMMAND(ID_PREVIOUS, OnPrevious) ON_COMMAND(ID_NEXT, OnNext) ON_UPDATE_COMMAND_UI(ID_PREVIOUS, OnUpdatePrevious) ON_UPDATE_COMMAND_UI(ID_NEXT, OnUpdateNext) ON_COMMAND(ID_PREVIEW_PREVIOUS, OnPreviewPrevious) ON_COMMAND(ID_PREVIEW_NEXT, OnPreviewNext) ON_UPDATE_COMMAND_UI(ID_PREVIEW_NEXT, OnUpdatePreviewNext) ON_UPDATE_COMMAND_UI(ID_PREVIEW_PREVIOUS, OnUpdatePreviewPrevious) ON_COMMAND(ID_VIEW_MULTI, OnViewMulti) ON_UPDATE_COMMAND_UI(ID_VIEW_MULTI, OnUpdateViewMulti) ON_UPDATE_COMMAND_UI(ID_INDICATOR_ZOOM,OnUpdateZoomPane) ON_UPDATE_COMMAND_UI(ID_INDICATOR_WH,OnUpdateWHPane) ON_UPDATE_COMMAND_UI(ID_INDICATOR_BPP,OnUpdateBppPane) ON_UPDATE_COMMAND_UI(ID_ZOOM_IN, OnUpdateZoomIn) ON_UPDATE_COMMAND_UI(ID_ZOOM_OUT, OnUpdateZoomOut) ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLBAR, OnUpdateViewToolbar) ON_COMMAND(ID_VIEW_TOOLBAR, OnViewToolbar) ON_COMMAND(ID_PRINT,OnFilePrint) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview) ON_MESSAGE(WM_HANDLEPALETTE,OnHandlePalette) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPrintingView construction/destruction CPrintingView::CPrintingView() { // TODO: add construction code here m_nImgWidth = 0; m_nImgHeight = 0; m_bPreview = FALSE; m_bIsOnePage = FALSE; m_bMulti = FALSE; m_bToolBar = TRUE; m_bPrint = FALSE; m_nMaxWidth = 0; m_nMaxHeight = 0; m_nPrintWidth = 0; m_nPrintHeight = 0; } CPrintingView::~CPrintingView() { } BOOL CPrintingView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CScrollView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CPrintingView drawing void CPrintingView::GetPrintInfo(CDC* pDC, CPrintDialog* dlgPrt, CDC* dcPrint,LBitmapBase* bmp) { if (pDC && dcPrint) { DEVMODE* pMode; pMode=dlgPrt->GetDevMode(); if(pMode) { int nXScrPPI=pDC->GetDeviceCaps(LOGPIXELSX); int nYScrPPI=pDC->GetDeviceCaps(LOGPIXELSY); int nXImgRes=bmp->GetXResolution(); int nYImgRes=bmp->GetYResolution(); int nQuality= 600; int nResolution=pMode->dmYResolution; m_nMaxWidth=dcPrint->GetDeviceCaps(HORZRES); m_nMaxHeight=dcPrint->GetDeviceCaps(VERTRES); m_nPrintWidth = ((m_nImgWidth * nQuality) / nXImgRes ); m_nPrintHeight = ((m_nImgHeight * nQuality) / nYImgRes ); if ((m_nPrintWidth >= m_nMaxWidth) || (m_nPrintHeight >= m_nMaxHeight)) { m_nPrintWidth = m_nAspectWidth; m_nPrintHeight = m_nAspectHeight; if (!m_bPrint) { m_nPrintWidth -= 60; m_nPrintHeight -= 60; } } } } } void CPrintingView::FindMaxAspect(LBitmapBase* bmp) { CDC* pDC=GetDC(); CDC dcPrint; int nPrintWidth,nPrintHeight; CPrintDialog dlgPrt(FALSE); dlgPrt.GetDefaults(); dcPrint.Attach(dlgPrt.m_pd.hDC); DEVMODE* pMode; pMode=dlgPrt.GetDevMode(); if(pMode) { int nXScrPPI=pDC->GetDeviceCaps(LOGPIXELSX); int nYScrPPI=pDC->GetDeviceCaps(LOGPIXELSY); int nImgWidth=m_nImgWidth; int nImgHeight=m_nImgHeight; int nXImgRes=bmp->GetXResolution(); int nYImgRes=bmp->GetYResolution(); int nQuality = 600; int nResolution=pMode->dmYResolution; m_nMaxWidth = dcPrint.GetDeviceCaps(HORZRES); m_nMaxHeight = dcPrint.GetDeviceCaps(VERTRES); nPrintWidth =( ( nImgWidth * nQuality ) / nXImgRes ); nPrintHeight =( ( nImgHeight * nQuality ) / nYImgRes ); int nZoomFactor = 100; if (nPrintWidth >= m_nMaxWidth || nPrintHeight >= m_nMaxHeight) { int nX = nPrintWidth - m_nMaxWidth; int nY = nPrintHeight - m_nMaxHeight; float nPercent; if (nX >= nY) nPercent = ((float)nPrintWidth / (float)nX); else nPercent = ((float)nPrintHeight / (float)nY); m_nAspectWidth = nPrintWidth - (int)(nPrintWidth / nPercent); m_nAspectHeight = nPrintHeight - (int)(nPrintHeight / nPercent); if (m_nAspectWidth > m_nMaxWidth || m_nAspectHeight > m_nMaxHeight) { nX = m_nAspectWidth - m_nMaxWidth; nY = m_nAspectHeight - m_nMaxHeight; if (nX >= nY) nPercent = ((float)m_nAspectWidth / (float)nX); else nPercent = ((float)m_nAspectHeight / (float)nY); m_nAspectWidth = m_nAspectWidth - (int)(m_nAspectWidth / nPercent); m_nAspectHeight = m_nAspectHeight - (int)(m_nAspectHeight / nPercent); } } while ((nPrintWidth < m_nMaxWidth) && (nPrintHeight < m_nMaxHeight)) { float nZoom = ((float)nZoomFactor/100); nImgWidth = (int)(nZoom * bmp->GetWidth()); nImgHeight = (int)(nZoom * bmp->GetHeight());; nPrintWidth =((nImgWidth * nQuality) / nXImgRes); nPrintHeight =((nImgHeight * nQuality) / nYImgRes); if (nPrintHeight >= m_nMaxHeight) { m_nAspectHeight = m_nMaxHeight; m_nAspectWidth = nPrintWidth; } else if (nPrintWidth >= m_nMaxWidth) { m_nAspectWidth = m_nMaxWidth; m_nAspectHeight = nPrintHeight; } nZoomFactor += 10; } } dcPrint.DeleteDC(); ReleaseDC(pDC); } void CPrintingView::OnDraw(CDC* pDC) { CPrintingDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (m_bmpList.IsCreated() || m_LeadBmp.IsAllocated()) { CRect rcPrv; CRect rcDest; HPALETTE hOldPal=NULL; HPALETTE hPalette=NULL; HDC hDC; LBitmapBase* pBitmap = &m_LeadBmp; if(m_bPreview) pBitmap = &m_bmpPreview; hDC = pDC->GetSafeHdc(); pBitmap->Paint()->SetDC(hDC); hPalette = pBitmap->GetPalette(); if (hPalette) { hOldPal=SelectPalette(hDC,hPalette,TRUE); pDC->RealizePalette(); } if (m_bPreview) { pDC->SelectStockObject(WHITE_BRUSH); pDC->Rectangle(m_nStart, 0, m_nStart + m_nMaxWidth, m_nMaxHeight); } pBitmap->Paint()->PaintDC(); pBitmap->Paint()->SetDC(NULL); if (hOldPal) SelectPalette(hDC,hOldPal,TRUE); } } ///////////////////////////////////////////////////////////////////////////// // CPrintingView printing BOOL CPrintingView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CPrintingView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CPrintingView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CPrintingView diagnostics #ifdef _DEBUG void CPrintingView::AssertValid() const { CScrollView::AssertValid(); } void CPrintingView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } CPrintingDoc* CPrintingView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrintingDoc))); return (CPrintingDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPrintingView message handlers void CPrintingView::OnFilePrint() { int nIndex; m_bPrint = TRUE; if ( m_LeadBmp.IsAllocated() ) { CPrintDialog dlgPrt(FALSE); if (dlgPrt.DoModal()==IDOK) { int nPages=0; int nCopies = dlgPrt.GetCopies(); CDC dcPrint; CDC* pDC=GetDC(); dcPrint.Attach(dlgPrt.GetPrinterDC()); if (m_bMulti) { nIndex = m_bmpList.GetCurrentIndex(); while (nPages < m_nBmpCount) { for (int i=0; i < nCopies; i++) { m_bmpList.GetItem(nPages,&m_bmpPreview, sizeof(BITMAPHANDLE)); float nZoom = (float)((float) m_pZoomFact[nPages].nZFact / 100.0); m_nImgWidth = (int)( nZoom * m_bmpPreview.GetWidth()); m_nImgHeight = (int)( nZoom * m_bmpPreview.GetHeight()); LPrint print(&m_bmpPreview); FindMaxAspect(&m_bmpPreview); GetPrintInfo(pDC, &dlgPrt, &dcPrint,&m_bmpPreview); if (m_bIsOnePage) { float xRes = (float)pDC->GetDeviceCaps(HORZRES); float yRes = (float)pDC->GetDeviceCaps(VERTRES); xRes /= 1000; yRes /= 1000; float nRes = (xRes+yRes) / 2; m_nMaxWidth = (int)(nRes * m_nMaxWidth) / 10; m_nMaxHeight = (int)(nRes * m_nMaxHeight) / 10; } else if (m_bPreview) { m_nMaxWidth = m_nMaxWidth / 10; m_nMaxHeight = m_nMaxHeight / 10; } L_UINT uflags = m_bmpPreview.GetDisplayMode(); m_bmpPreview.SetDisplayMode(0,0); if ( (dcPrint.GetDeviceCaps(NUMCOLORS) > 2) || (dcPrint.GetDeviceCaps(BITSPIXEL) != 1) ) m_bmpPreview.SetDisplayMode(DISPLAYMODE_DITHEREDPAINT | DISPLAYMODE_INDEXEDPAINT,0); HDC hPrintDC = print.GetPrinterDC(); print.Print(hPrintDC, 1, 1, m_nPrintWidth, m_nPrintHeight); m_bmpPreview.SetDisplayMode (DISPLAYMODE_RESETPOSITIONS, uflags); } nPages++; } m_bmpList.GetItem(nIndex, &m_bmpPreview, sizeof(BITMAPHANDLE)); } else { for (int i=0; i < nCopies; i++) { nIndex = m_bmpList.GetCurrentIndex(); LPrint print(&m_LeadBmp); float nZoom = (float)((float) m_pZoomFact[nIndex].nZFact / 100.0); m_nImgWidth = (int)( nZoom * m_LeadBmp.GetWidth()); m_nImgHeight = (int)( nZoom * m_LeadBmp.GetHeight()); FindMaxAspect(&m_LeadBmp); GetPrintInfo(pDC, &dlgPrt, &dcPrint,&m_LeadBmp); if (m_bIsOnePage) { float xRes = (float)pDC->GetDeviceCaps(HORZRES); float yRes = (float)pDC->GetDeviceCaps(VERTRES); xRes /= 1000; yRes /= 1000; float nRes = (xRes+yRes) / 2; m_nMaxWidth = (int)(nRes * m_nMaxWidth) / 10; m_nMaxHeight = (int)(nRes * m_nMaxHeight) / 10; } else if (m_bPreview) { m_nMaxWidth = m_nMaxWidth / 10; m_nMaxHeight = m_nMaxHeight / 10; } L_UINT uflags = m_LeadBmp.GetDisplayMode(); m_LeadBmp.SetDisplayMode(0,0); if ( (dcPrint.GetDeviceCaps(NUMCOLORS) > 2) || (dcPrint.GetDeviceCaps(BITSPIXEL) != 1) ) m_LeadBmp.SetDisplayMode(DISPLAYMODE_DITHEREDPAINT | DISPLAYMODE_INDEXEDPAINT,0); HDC hPrintDC = print.GetPrinterDC(); print.Print(hPrintDC, 1, 1, m_nPrintWidth,m_nPrintHeight); m_LeadBmp.SetDisplayMode (DISPLAYMODE_RESETPOSITIONS, uflags); } } ReleaseDC(pDC); dcPrint.DeleteDC(); } } m_bPrint = FALSE; } void CPrintingView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if ( bActivate ) { if (m_bPreview) { CMainFrame* pMain=(CMainFrame*)GetParentOwner(); pMain->SetButtonStatus(m_bIsOnePage); ShowToolBar(FALSE); } else { ShowToolBar(m_bToolBar); } ShowBar(m_bPreview); HandlePalette(WM_QUERYNEWPALETTE,0); } CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView); } void CPrintingView::OnFilePrintPreview() { int nIndex; L_UINT nRet; CPrintingApp* pApp = (CPrintingApp*)AfxGetApp(); nIndex = m_bmpList.GetCurrentIndex(); if (m_bmpList.GetItemsCount() > 1) nRet=m_bmpList.GetItem(nIndex, &m_bmpPreview, sizeof(BITMAPHANDLE)); else { m_bmpPreview = m_LeadBmp; nRet = SUCCESS; } if (nRet == SUCCESS ) { int nClientWidth ; CRect rcPrv; CSize size; CDC dcPrint; CPrintDialog dlgPrt(FALSE); CMainFrame* pMain=(CMainFrame*)GetParentOwner(); dlgPrt.GetDefaults(); CDC* pDC=GetDC(); m_bToolBar = pMain->IsToolBarVisible(); m_bIsOnePage=FALSE; m_bPreview=TRUE; ShowBar(m_bPreview); ShowToolBar(FALSE); pMain->SetButtonStatus(FALSE); m_nImgWidth = (int)(m_bmpPreview.GetWidth() * ((float)m_pZoomFact[nIndex].nZFact / 100.0)); m_nImgHeight = (int)(m_bmpPreview.GetHeight() * ((float)m_pZoomFact[nIndex].nZFact / 100.0)); if(dlgPrt.m_pd.hDC) { dcPrint.Attach(dlgPrt.m_pd.hDC); FindMaxAspect(&m_bmpPreview); GetPrintInfo(pDC,&dlgPrt,&dcPrint,&m_LeadBmp); m_nMaxWidth = m_nMaxWidth / 10; m_nMaxHeight = m_nMaxHeight / 10; m_nPrintWidth = m_nPrintWidth / 10; m_nPrintHeight = m_nPrintHeight / 10; nClientWidth = pDC->GetDeviceCaps(HORZRES); m_nStart= (L_INT)((nClientWidth / 2) - (m_nMaxWidth / 2)); rcPrv.SetRect(m_nStart + 3, 3, m_nStart + m_nPrintWidth + 3, m_nPrintHeight + 3); m_bmpPreview.SetDstRect(&rcPrv); size.cx = m_nMaxWidth; size.cy = m_nMaxHeight; SetScrollSizes(MM_TEXT,size); HandlePalette(WM_QUERYNEWPALETTE,0); dcPrint.DeleteDC(); } ReleaseDC(pDC); } } void CPrintingView::ShowBar(BOOL bShow) { CMainFrame* pMain=(CMainFrame*)GetParentOwner(); pMain->UpdatePreviewToolBar(bShow); if (m_bPreview!=bShow) { m_bPreview=bShow; RedrawWindow(); } } void CPrintingView::OnClosePreview() { int nIndex = m_bmpList.GetCurrentIndex(); m_bPreview=FALSE; m_bIsOnePage=FALSE; ShowBar(m_bPreview); ShowToolBar(m_bToolBar); m_bmpList.GetItem(nIndex, &m_LeadBmp, sizeof(BITMAPHANDLE)); float nZoom=(float)((float) m_pZoomFact[nIndex].nZFact / 100.0); m_nImgWidth =(int)( nZoom * m_LeadBmp.GetWidth()); m_nImgHeight =(int)( nZoom * m_LeadBmp.GetHeight()); CRect rcImg(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcImg); CSize size; size.cx=m_nImgWidth; size.cy=m_nImgHeight; SetScrollSizes(MM_TEXT,size); HandlePalette(WM_QUERYNEWPALETTE,0); } int CPrintingView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CScrollView::OnCreate(lpCreateStruct) == -1) return -1; HBRUSH hOldBrush=(HBRUSH)GetClassLong(GetSafeHwnd(),GCL_HBRBACKGROUND); HBRUSH hNewBrush=CreateSolidBrush(RGB(129,129,129)); SetClassLong(GetSafeHwnd(),GCL_HBRBACKGROUND,(LONG)hNewBrush); if (!hOldBrush) DeleteObject(hOldBrush); return 0; } void CPrintingView::OnOnePage() { int nIndex; CPrintingApp* pApp = (CPrintingApp*)AfxGetApp(); nIndex = m_bmpList.GetCurrentIndex(); CMainFrame* pMain=(CMainFrame*)GetParentOwner(); m_bIsOnePage=pMain->GetButtonStatus(); CDC* pDC=GetDC(); CDC dcPrint; CPrintDialog dlgPrt(FALSE); dlgPrt.GetDefaults(); dcPrint.Attach(dlgPrt.m_pd.hDC); m_nImgWidth = (int)(m_bmpPreview.GetWidth() * ((float)m_pZoomFact[nIndex].nZFact / 100.0)); m_nImgHeight = (int)(m_bmpPreview.GetHeight() * ((float)m_pZoomFact[nIndex].nZFact / 100.0)); FindMaxAspect(&m_bmpPreview); GetPrintInfo(pDC,&dlgPrt,&dcPrint,&m_bmpPreview); CSize size; if (m_bIsOnePage) { float xRes=(float)pDC->GetDeviceCaps(HORZRES); float yRes=(float)pDC->GetDeviceCaps(VERTRES); xRes/=1000; yRes/=1000; float nRes=(xRes+yRes) /2; m_nImgWidth =(int)(nRes * m_nImgWidth)/10; m_nImgHeight =(int)(nRes * m_nImgHeight)/10; m_nMaxWidth =(int)(nRes * m_nMaxWidth)/10; m_nMaxHeight =(int)(nRes * m_nMaxHeight)/10; m_nPrintWidth =(int)(nRes * m_nPrintWidth)/10; m_nPrintHeight =(int)(nRes * m_nPrintHeight)/10; } else { m_nMaxWidth = m_nMaxWidth/10; m_nMaxHeight = m_nMaxHeight/10; m_nPrintWidth = m_nPrintWidth/10; m_nPrintHeight = m_nPrintHeight/10; } CRect rcPrv; int nClientWidth = pDC->GetDeviceCaps(HORZRES); m_nStart= (L_INT)((nClientWidth / 2) - (m_nMaxWidth/2)); rcPrv.SetRect(m_nStart + 3, 3, m_nStart + m_nPrintWidth + 3, m_nPrintHeight + 3); m_bmpPreview.SetDstRect(&rcPrv); dcPrint.DeleteDC(); ReleaseDC(pDC); size.cx = m_nMaxWidth; size.cy = m_nMaxHeight; SetScrollSizes(MM_TEXT,size); RedrawWindow(); } void CPrintingView::ClosePreview() { OnClosePreview(); } void CPrintingView::OnUpdateFilePrintPreview(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bPreview); CPrintDialog dlg(FALSE); if (dlg.GetDefaults()) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); // attach to the DC we were given CDC dc; dc.Attach(dlg.m_pd.hDC); dc.DeleteDC(); // Note: no need to call Detach() because we want the CDC destructor // to call FreeDC() on the DC we borrowed from the common dialog } void CPrintingView::OnUpdateViewZooming(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bPreview); } void CPrintingView::OnUpdateOnePage(CCmdUI* pCmdUI) { CRect rcClient; GetClientRect(&rcClient); int Height=rcClient.Height(); int nMaxHeight = m_nMaxHeight * 10; if (nMaxHeight <= Height ) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } void CPrintingView::OnPrevious() { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (nIndex > 0) { nIndex-=1; L_UINT nRet=m_bmpList.GetItem(nIndex,&m_LeadBmp,sizeof(BITMAPHANDLE)); if (nRet == SUCCESS) { float nZoom=(float)((float) m_pZoomFact[nIndex].nZFact / 100.0); m_nImgWidth =(int)( nZoom * m_LeadBmp.GetWidth()); m_nImgHeight =(int)( nZoom * m_LeadBmp.GetHeight()); CRect rcImg(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcImg); CSize size; size.cx=m_nImgWidth; size.cy=m_nImgHeight; SetScrollSizes(MM_TEXT,size); FindMaxAspect(&m_LeadBmp); HandlePalette(WM_QUERYNEWPALETTE,0); InvalidateRect(NULL,true); UpdateWindow(); } } } void CPrintingView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize size; int nIndex; L_INT nRet; CPrintingApp* pApp = (CPrintingApp*)AfxGetApp(); if (pApp->m_nPageNumber == 0) { nIndex = pApp->m_nPageNumber; pApp->m_nPageNumber = 1; } else nIndex = pApp->m_nPageNumber-1; if (m_bmpList.GetItemsCount() > 1) { nRet=m_bmpList.GetItem(nIndex, &m_LeadBmp,sizeof(BITMAPHANDLE)); if (nRet == SUCCESS) { m_bmpList.SetCurrentIndex(nIndex); m_nBmpCount=m_bmpList.GetItemsCount(); m_nImgWidth=m_LeadBmp.GetWidth(); m_nImgHeight=m_LeadBmp.GetHeight(); CRect rcImg(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcImg); size.cx=m_nImgWidth; size.cy=m_nImgHeight; m_pZoomFact=new IMAGEZOOMFACT[m_nBmpCount]; for (int i=0;iEnable(FALSE); else pCmdUI->Enable(TRUE); } void CPrintingView::OnUpdateNext(CCmdUI* pCmdUI) { if (m_nBmpCount == 1) pCmdUI->Enable(FALSE); else { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (nIndex == m_nBmpCount-1) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } } void CPrintingView::OnPreviewPrevious() { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (nIndex > 0) { nIndex-=1; L_UINT nRet=m_bmpList.GetItem(nIndex,&m_bmpPreview,sizeof(BITMAPHANDLE)); if (nRet == SUCCESS) { m_bmpList.GetItem(nIndex,&m_LeadBmp,sizeof(BITMAPHANDLE)); CDC* pDC=GetDC(); CDC dcPrint; CPrintDialog dlgPrt(FALSE); dlgPrt.GetDefaults(); dcPrint.Attach(dlgPrt.m_pd.hDC); CRect rcDst; m_bmpPreview.GetRects(NULL,NULL,&rcDst,NULL); float nZoom=(float)((float) m_pZoomFact[nIndex].nZFact / 100.0); m_nImgWidth =(int)( nZoom * m_bmpPreview.GetWidth()); m_nImgHeight =(int)( nZoom * m_bmpPreview.GetHeight()); FindMaxAspect(&m_bmpPreview); GetPrintInfo(pDC,&dlgPrt,&dcPrint,&m_bmpPreview); dcPrint.DeleteDC(); CSize size; if (m_bIsOnePage) { float xRes=(float)pDC->GetDeviceCaps(HORZRES); float yRes=(float)pDC->GetDeviceCaps(VERTRES); xRes/=1000; yRes/=1000; float nRes=(xRes+yRes) /2; m_nImgWidth =(int)(nRes * m_nImgWidth)/10; m_nImgHeight =(int)(nRes * m_nImgHeight)/10; m_nMaxWidth =(int)(nRes * m_nMaxWidth)/10; m_nMaxHeight =(int)(nRes * m_nMaxHeight)/10; m_nPrintWidth =(int)(nRes * m_nPrintWidth)/10; m_nPrintHeight =(int)(nRes * m_nPrintHeight)/10; } else { m_nMaxWidth = m_nMaxWidth/10; m_nMaxHeight = m_nMaxHeight/10; m_nPrintWidth = m_nPrintWidth/10; m_nPrintHeight = m_nPrintHeight/10; } CRect rcPrv; int nClientWidth = pDC->GetDeviceCaps(HORZRES); m_nStart=(int)((nClientWidth / 2) - (m_nMaxWidth/2)); rcPrv.SetRect(m_nStart + 3, 3, m_nStart + m_nPrintWidth + 3,m_nPrintHeight + 3); m_bmpPreview.SetDstRect(&rcPrv); dcPrint.DeleteDC(); ReleaseDC(pDC); size.cx = m_nMaxWidth; size.cy = m_nMaxHeight; SetScrollSizes(MM_TEXT,size); HandlePalette(WM_QUERYNEWPALETTE,0); } } } void CPrintingView::OnPreviewNext() { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (nIndex < m_nBmpCount-1) { nIndex+=1; L_UINT nRet=m_bmpList.GetItem(nIndex,&m_bmpPreview,sizeof(BITMAPHANDLE)); if (nRet == SUCCESS) { m_bmpList.GetItem(nIndex,&m_LeadBmp,sizeof(BITMAPHANDLE)); CDC* pDC=GetDC(); CDC dcPrint; CPrintDialog dlgPrt(FALSE); dlgPrt.GetDefaults(); dcPrint.Attach(dlgPrt.m_pd.hDC); float nZoom=(float)((float) m_pZoomFact[nIndex].nZFact / 100.0); m_nImgWidth =(int)( nZoom * m_bmpPreview.GetWidth()); m_nImgHeight =(int)( nZoom * m_bmpPreview.GetHeight()); FindMaxAspect(&m_bmpPreview); GetPrintInfo(pDC,&dlgPrt,&dcPrint,&m_bmpPreview); dcPrint.DeleteDC(); CSize size; if (m_bIsOnePage) { float xRes=(float)pDC->GetDeviceCaps(HORZRES); float yRes=(float)pDC->GetDeviceCaps(VERTRES); xRes/=1000; yRes/=1000; float nRes=(xRes+yRes) /2; m_nImgWidth =(int)(nRes * m_nImgWidth)/10; m_nImgHeight =(int)(nRes * m_nImgHeight)/10; m_nMaxWidth =(int)(nRes * m_nMaxWidth)/10; m_nMaxHeight =(int)(nRes * m_nMaxHeight)/10; m_nPrintWidth =(int)(nRes * m_nPrintWidth)/10; m_nPrintHeight =(int)(nRes * m_nPrintHeight)/10; } else { m_nMaxWidth = m_nMaxWidth/10; m_nMaxHeight = m_nMaxHeight/10; m_nPrintWidth = m_nPrintWidth/10; m_nPrintHeight = m_nPrintHeight/10; } CRect rcPrv; int nClientWidth = pDC->GetDeviceCaps(HORZRES); m_nStart=(int)((nClientWidth / 2) - (m_nMaxWidth/2)); rcPrv.SetRect(m_nStart + 3, 3, m_nStart + m_nPrintWidth + 3, m_nPrintHeight + 3); m_bmpPreview.SetDstRect(&rcPrv); dcPrint.DeleteDC(); ReleaseDC(pDC); size.cx = m_nMaxWidth; size.cy = m_nMaxHeight; SetScrollSizes(MM_TEXT,size); HandlePalette(WM_QUERYNEWPALETTE,0); } } } void CPrintingView::OnUpdatePreviewNext(CCmdUI* pCmdUI) { if (m_nBmpCount == 1) pCmdUI->Enable(FALSE); else { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (nIndex == m_nBmpCount-1) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } } void CPrintingView::OnUpdatePreviewPrevious(CCmdUI* pCmdUI) { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (nIndex == 0) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } void CPrintingView::OnViewMulti() { m_bMulti=!m_bMulti; } void CPrintingView::OnUpdateViewMulti(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bMulti); if (m_nBmpCount == 1) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } void CPrintingView::OnNormal() { L_INT nIndex; nIndex = m_bmpList.GetCurrentIndex(); m_nImgWidth=m_LeadBmp.GetWidth(); m_nImgHeight=m_LeadBmp.GetHeight(); m_pZoomFact[nIndex].nZFact = 100; CRect rcDst; rcDst.SetRect(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcDst); CSize imgSize; imgSize.cx=m_nImgWidth; imgSize.cy=m_nImgHeight; SetScrollSizes(MM_TEXT,imgSize); RedrawWindow(); } void CPrintingView::OnZoomOut() { L_INT nIndex=m_bmpList.GetCurrentIndex(); m_pZoomFact[nIndex].nZFact -= 10; if (m_pZoomFact[nIndex].nZFact < 1) m_pZoomFact[nIndex].nZFact = 1; float nZoom =((float)m_pZoomFact[nIndex].nZFact / 100); m_nImgWidth =(int)( nZoom * m_LeadBmp.GetWidth()); m_nImgHeight =(int)( nZoom * m_LeadBmp.GetHeight());; CRect rcDst; rcDst.SetRect(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcDst); CSize imgSize(m_nImgWidth,m_nImgHeight); SetScrollSizes(MM_TEXT,imgSize); RedrawWindow(); } void CPrintingView::OnZoomIn() { L_INT nIndex=m_bmpList.GetCurrentIndex(); m_pZoomFact[nIndex].nZFact += 10; if (m_pZoomFact[nIndex].nZFact > 800) m_pZoomFact[nIndex].nZFact = 800; float nZoom=(float)m_pZoomFact[nIndex].nZFact / 100; m_nImgWidth =(int)( nZoom * m_LeadBmp.GetWidth()); m_nImgHeight =(int)( nZoom * m_LeadBmp.GetHeight()); CRect rcDst; rcDst.SetRect(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcDst); CSize imgSize; imgSize.cx=m_nImgWidth; imgSize.cy=m_nImgHeight; SetScrollSizes(MM_TEXT,imgSize); RedrawWindow(); } void CPrintingView::OnViewZooming() { CZoomDlg dlg; int nCurIndex=m_bmpList.GetCurrentIndex(); dlg.m_nZoom = m_pZoomFact[nCurIndex].nZFact; if ( dlg.DoModal() == IDOK ) { CDC* pDC=GetDC(); CDC dcPrint; CPrintDialog dlgPrt(FALSE); dlgPrt.GetDefaults(); dcPrint.Attach(dlgPrt.m_pd.hDC); GetPrintInfo(pDC,&dlgPrt,&dcPrint,&m_LeadBmp); dcPrint.DeleteDC(); m_pZoomFact[nCurIndex].nZFact = dlg.m_nZoom; float nZoom=(float)m_pZoomFact[nCurIndex].nZFact / 100; m_nImgWidth = (int)( nZoom * m_LeadBmp.GetWidth()); m_nImgHeight = (int)( nZoom * m_LeadBmp.GetHeight()); CRect rcImg(0,0,m_nImgWidth,m_nImgHeight); m_LeadBmp.SetDstRect(&rcImg); CSize size; size.cx=m_nImgWidth; size.cy=m_nImgHeight; SetScrollSizes(MM_TEXT,size); RedrawWindow(); } } LRESULT CPrintingView::OnHandlePalette(WPARAM wParam,LPARAM lParam) { if(lParam==TRUE) { HandlePalette(WM_PALETTECHANGED,(HWND)wParam); InvalidateRect(NULL,false); UpdateWindow(); } else { if(HandlePalette(WM_QUERYNEWPALETTE,0)==FALSE) { InvalidateRect(NULL,false); UpdateWindow(); } } return TRUE; } L_BOOL CPrintingView::HandlePalette(UINT uMsg,HWND hWnd) { HDC hDC; LBitmapBase* pBitmap = &m_LeadBmp; if(m_bPreview) pBitmap = &m_bmpPreview; switch(uMsg) { case WM_PALETTECHANGED: if(m_hWnd== hWnd) return TRUE; case WM_SYSCOLORCHANGE: case WM_QUERYNEWPALETTE: hDC = ::GetDC(m_hWnd); HPALETTE hPalette = pBitmap->CreatePaintPalette(hDC); L_UINT uColor=0; if(hPalette) { HPALETTE oldPalette = ::SelectPalette(hDC,hPalette,(uMsg==WM_PALETTECHANGED)); uColor=::RealizePalette(hDC); ::SelectPalette(hDC,oldPalette,TRUE); } ::ReleaseDC(m_hWnd,hDC); InvalidateRect(NULL,false); UpdateWindow(); break; } return FALSE; } void CPrintingView::OnUpdateZoomPane(CCmdUI* pCmdUI) { L_INT nIndex; CString str; nIndex=m_bmpList.GetCurrentIndex(); str.Format(_T("Zoom: %d%%"),m_pZoomFact[nIndex].nZFact); pCmdUI->SetText(str); } void CPrintingView::OnUpdateWHPane(CCmdUI* pCmdUI) { int nWidth,nHeight; CString str; CRect rcDst; if (m_bPreview) { m_bmpPreview.GetRects(NULL,NULL,&rcDst,NULL); nWidth =rcDst.Width(); nHeight =rcDst.Height(); } else { m_LeadBmp.GetRects(NULL,NULL,&rcDst,NULL); nWidth =rcDst.Width(); nHeight =rcDst.Height(); } str.Format(_T("WxH: %dx%d"),nWidth,nHeight); pCmdUI->SetText(str); } void CPrintingView::OnUpdateBppPane(CCmdUI* pCmdUI) { L_INT nBPP; CString str; if (m_bPreview) nBPP=m_bmpPreview.GetBitsPerPixel(); else nBPP=m_LeadBmp.GetBitsPerPixel(); str.Format(_T("BPP: %d"),nBPP); pCmdUI->SetText(str); } void CPrintingView::OnUpdateZoomIn(CCmdUI* pCmdUI) { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (m_pZoomFact[nIndex].nZFact == 800) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } void CPrintingView::OnUpdateZoomOut(CCmdUI* pCmdUI) { L_INT nIndex=m_bmpList.GetCurrentIndex(); if (m_pZoomFact[nIndex].nZFact == 1) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); } void CPrintingView::ShowToolBar(BOOL bShow) { CMainFrame* pMain=(CMainFrame*)GetParentOwner(); pMain->UpdateMainToolBar(bShow); } /*void CPrintingView::OnUpdateViewToolbar(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bPreview); CMainFrame* pMain=(CMainFrame*)GetParentOwner(); BOOL bIsVisible = pMain->IsToolBarVisible(); pCmdUI->SetCheck(bIsVisible); }*/ void CPrintingView::OnUpdateViewToolbar(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CMainFrame* pMain=(CMainFrame*)GetParentOwner(); if (m_bPreview) pCmdUI->Enable(FALSE); else { pCmdUI->Enable(TRUE); pCmdUI->SetCheck(pMain->IsToolBarVisible()); } } void CPrintingView::OnViewToolbar() { // TODO: Add your command handler code here CMainFrame* pMain=(CMainFrame*)GetParentOwner(); m_bToolBar = !m_bToolBar; pMain->UpdateMainToolBar(m_bToolBar); }