oledoc2.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "stdafx.h"
  11. #ifdef AFX_OLE_SEG
  12. #pragma code_seg(AFX_OLE_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // COleDocument printing support
  20. BOOL COleDocument::ApplyPrintDevice(const DVTARGETDEVICE* ptd)
  21. {
  22. ASSERT_VALID(this);
  23. ASSERT(ptd == NULL || AfxIsValidAddress(ptd, (size_t)ptd->tdSize, FALSE));
  24. // allocate copy of target device
  25. if (ptd != NULL)
  26. {
  27. DVTARGETDEVICE* ptdNew = _AfxOleCopyTargetDevice((DVTARGETDEVICE*)ptd);
  28. if (ptdNew == NULL)
  29. return FALSE;
  30. ptd = ptdNew;
  31. }
  32. // remove old target device from memory
  33. CoTaskMemFree(m_ptd);
  34. m_ptd = (DVTARGETDEVICE*)ptd;
  35. // Note: updating all the client items does not refresh the pres. cache
  36. POSITION pos = GetStartPosition();
  37. COleClientItem* pItem;
  38. while ((pItem = GetNextClientItem(pos)) != NULL)
  39. {
  40. // update all the client items with new target device
  41. pItem->SetPrintDevice(ptd);
  42. }
  43. return TRUE;
  44. }
  45. BOOL COleDocument::ApplyPrintDevice(const PRINTDLG* ppd)
  46. {
  47. ASSERT_VALID(this);
  48. ASSERT(ppd == NULL || AfxIsValidAddress(ppd, sizeof(*ppd), FALSE));
  49. DVTARGETDEVICE* ptd = NULL;
  50. if (ppd != NULL)
  51. ptd = _AfxOleCreateTargetDevice((PRINTDLG*)ppd);
  52. BOOL bResult = ApplyPrintDevice(ptd);
  53. CoTaskMemFree(ptd);
  54. return bResult;
  55. }
  56. /////////////////////////////////////////////////////////////////////////////