home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / oledoc2.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  2KB  |  67 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_OLE_SEG
  14. #pragma code_seg(AFX_OLE_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // COleDocument printing support
  24.  
  25. BOOL COleDocument::ApplyPrintDevice(const DVTARGETDEVICE* ptd)
  26. {
  27.     ASSERT_VALID(this);
  28.     ASSERT(ptd == NULL || AfxIsValidAddress(ptd, (size_t)ptd->tdSize, FALSE));
  29.  
  30.     // allocate copy of target device
  31.     if (ptd != NULL)
  32.     {
  33.         DVTARGETDEVICE* ptdNew = _AfxOleCopyTargetDevice((DVTARGETDEVICE*)ptd);
  34.         if (ptdNew == NULL)
  35.             return FALSE;
  36.         ptd = ptdNew;
  37.     }
  38.     // remove old target device from memory
  39.     CoTaskMemFree(m_ptd);
  40.     m_ptd = (DVTARGETDEVICE*)ptd;
  41.  
  42.     // Note: updating all the client items does not refresh the pres. cache
  43.     POSITION pos = GetStartPosition();
  44.     COleClientItem* pItem;
  45.     while ((pItem = GetNextClientItem(pos)) != NULL)
  46.     {
  47.         // update all the client items with new target device
  48.         pItem->SetPrintDevice(ptd);
  49.     }
  50.     return TRUE;
  51. }
  52.  
  53. BOOL COleDocument::ApplyPrintDevice(const PRINTDLG* ppd)
  54. {
  55.     ASSERT_VALID(this);
  56.     ASSERT(ppd == NULL || AfxIsValidAddress(ppd, sizeof(*ppd), FALSE));
  57.     DVTARGETDEVICE* ptd = NULL;
  58.     if (ppd != NULL)
  59.         ptd = _AfxOleCreateTargetDevice((PRINTDLG*)ppd);
  60.  
  61.     BOOL bResult = ApplyPrintDevice(ptd);
  62.     CoTaskMemFree(ptd);
  63.     return bResult;
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67.