home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // PrintDr.cpp : Implementation of CPrintDr
- #include "stdafx.h"
- #include "PrintCAD.h"
- #include "PrintDr.h"
-
- /////////////////////////////////////////////////////////////////////////////
- // CPrintDr
-
- COleVariant varMissing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
- COleVariant varTrue(1L);
- COleVariant varFalse(0L);
-
- #define RC_REQURE RC_BITBLT | RC_BITMAP64 /*| RC_STRETCHBLT */
-
-
- STDMETHODIMP CPrintDr::PrintAll(LPDISPATCH WhichDrawing, long pHDC)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- IDrawing* pIDrawing = NULL;
- pIDrawing = (IDrawing*) WhichDrawing;
- m_sDrawMode = DM_BLACK;
- m_pView = NULL;
-
- if (pIDrawing == NULL)
- return FALSE;
-
-
- HDC hPrintDC = (HDC) pHDC;
- if (hPrintDC != NULL)
- {
- int caps = ::GetDeviceCaps(hPrintDC, RASTERCAPS);
-
- if ((caps & (RC_REQURE)) != (RC_REQURE))
- {
- CString cstrMessage;
- cstrMessage.Format(_T("Sorry, can't use your printer.\n \
- Printer raster capabilities is %x"), caps);
- AfxMessageBox(cstrMessage);
- return FALSE;
- }
-
- BOOL bMonochrom = FALSE;
- // Setup printer DC
- CDC *pPrintDC = new CDC;
- pPrintDC->Attach(hPrintDC);
-
- pPrintDC->m_bPrinting = TRUE;
-
- HDC hScreenIC = CreateIC(_T("Display"), NULL, NULL, NULL);
- int logpxScreen = ::GetDeviceCaps(hScreenIC, LOGPIXELSX);
- int logpyScreen = ::GetDeviceCaps(hScreenIC, LOGPIXELSY);
- DeleteDC(hScreenIC);
-
- int iOldMode = pPrintDC->SetMapMode(MM_TEXT);
-
- int logpxPage = pPrintDC->GetDeviceCaps(LOGPIXELSX);
- int logpyPage = pPrintDC->GetDeviceCaps(LOGPIXELSY);
-
- CSize cszOldPage = pPrintDC->ScaleWindowExt(logpxPage, logpxScreen,
- logpyPage, logpyScreen);
-
- int cxPage = (int)(pPrintDC->GetDeviceCaps(HORZRES) * 0.9 + 0.5);
- int cyPage = (int)(pPrintDC->GetDeviceCaps(VERTRES) * 0.9 + 0.5);
-
- CRect rcPage(0, 0, cxPage, cyPage);
-
- CSize cszOldViewport = pPrintDC->SetViewportExt(cxPage, -cyPage);
-
- if (hPrintDC != NULL)
- {
-
- Views *pViews = NULL;
- View *pView = NULL;
-
- short sOldDrawMode = m_sDrawMode;
-
- HRESULT hRes = S_OK;
-
- DOCINFO docInfo;
- memset(&docInfo, 0, sizeof(DOCINFO));
- docInfo.cbSize = sizeof(DOCINFO);
- docInfo.lpszDocName = _T("TurboCAD drawing");
-
- pPrintDC->StartDoc(&docInfo);
- pPrintDC->StartPage();
- // ABT 052097
- // According to MS( see mfc\src\viewprnt.cpp)
- // must call OnPrepareDC on newer versions of Windows because
- // StartPage now resets the device attributes.
- ASSERT_VALID(pPrintDC);
- UNUSED(pPrintDC); // unused in release builds
-
- try
- {
- hRes = pIDrawing->get_Views(&pViews);
- CHECK_HRESULT(hRes)
-
- COleVariant varHwnd(varMissing);
- COleVariant varDC((const long)hPrintDC);
-
- hRes = pViews->Add(&varHwnd, &varDC, &pView);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_Update(FALSE);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_CenterOnExtents(TRUE);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_MappingMode(MM_TEXT);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_Margins(FALSE);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_FixedAspectRatio(TRUE);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_ScreenLeft(0);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_ScreenTop(0);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_ScreenWidth(cxPage);
- CHECK_HRESULT(hRes)
-
- hRes = pView->put_ScreenHeight(cyPage);
- CHECK_HRESULT(hRes)
-
- SetDrawModeEx(DM_WHITE | DM_INVERT);
-
- hRes = pView->ZoomToExtents();
- CHECK_HRESULT(hRes)
-
- }
- catch (...)
- {
- }
-
- SetDrawModeEx(sOldDrawMode);
-
- if (pView != NULL)
- pView->Release();
-
- if (pViews != NULL)
- pViews->Release();
-
-
- }
-
- pPrintDC->EndPage();
- pPrintDC->SetViewportExt(cszOldViewport);
- pPrintDC->SetWindowExt(cszOldPage);
- pPrintDC->SetMapMode(iOldMode);
- int nResult = pPrintDC->EndDoc();
- ASSERT(nResult >= 0);
- pPrintDC->Detach();
-
- delete pPrintDC;
-
- }
-
- // TODO: Add your implementation code here
-
- return S_OK;
- }
-
-
-
- void CPrintDr::SetDrawModeEx(short nNewValue)
- {
- m_sDrawMode = nNewValue;
- ASSERT((m_sDrawMode & DM_CHECKBITMAP) != DM_CHECKBITMAP);
-
- switch (m_sDrawMode)
- {
- case DM_WHITE:
- m_clrBackGround = RGB(255, 255, 255);
- break;
- case DM_INVERT | DM_WHITE:
- m_clrBackGround = RGB(0, 0, 0);
- break;
- case DM_INVERT | DM_BLACK:
- m_clrBackGround = RGB(255, 255, 255);
- break;
- case DM_BLACK:
- default:
- m_clrBackGround = RGB(0, 0, 0);
- break;
- }
-
- }
-
-
-
-