home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / WINGDI.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  31.3 KB  |  1,276 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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_CORE2_SEG
  14. #pragma code_seg(AFX_CORE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Diagnostic Output
  24. #ifdef _DEBUG
  25. CDumpContext& AFXAPI operator<<(CDumpContext& dc, SIZE size)
  26. {
  27.     return dc << "(" << size.cx << " x " << size.cy << ")";
  28. }
  29.  
  30. CDumpContext& AFXAPI operator<<(CDumpContext& dc, POINT point)
  31. {
  32.     return dc << "(" << point.x << ", " << point.y << ")";
  33. }
  34.  
  35. CDumpContext& AFXAPI operator<<(CDumpContext& dc, const RECT& rect)
  36. {
  37.     return dc << "(L " << rect.left << ", T " << rect.top << ", R " <<
  38.         rect.right << ", B " << rect.bottom << ")";
  39. }
  40. #endif //_DEBUG
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CDC
  44.  
  45. CDC::CDC()
  46. {
  47.     m_hDC = NULL;
  48.     m_hAttribDC = NULL;
  49.     m_bPrinting = FALSE;
  50. }
  51.  
  52. #ifdef _DEBUG
  53. void CDC::AssertValid() const
  54. {
  55.     CObject::AssertValid();
  56. }
  57.  
  58. void CDC::Dump(CDumpContext& dc) const
  59. {
  60.     CObject::Dump(dc);
  61.  
  62.     dc << "m_hDC = " << (UINT)m_hDC;
  63.     dc << "\nm_hAttribDC = " << (UINT)m_hAttribDC;
  64.     dc << "\nm_bPrinting = " << m_bPrinting;
  65.  
  66.     dc << "\n";
  67. }
  68. #endif //_DEBUG
  69.  
  70. static CHandleMap* afxMapHDC(BOOL bCreate = FALSE);
  71.  
  72. static CHandleMap* afxMapHDC(BOOL bCreate)
  73. {
  74.     AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
  75.     if (pState->m_pmapHDC == NULL && bCreate)
  76.     {
  77.         BOOL bEnable = AfxEnableMemoryTracking(FALSE);
  78. #ifndef _AFX_PORTABLE
  79.         _PNH pnhOldHandler = AfxSetNewHandler(&AfxCriticalNewHandler);
  80. #endif
  81.         pState->m_pmapHDC = new CHandleMap(RUNTIME_CLASS(CDC),
  82.             offsetof(CDC, m_hDC), 2);
  83.  
  84. #ifndef _AFX_PORTABLE
  85.         AfxSetNewHandler(pnhOldHandler);
  86. #endif
  87.         AfxEnableMemoryTracking(bEnable);
  88.     }
  89.     return pState->m_pmapHDC;
  90. }
  91.  
  92. void PASCAL CDC::DeleteTempMap()
  93. {
  94.     CHandleMap* pMap = afxMapHDC();
  95.     if (pMap != NULL)
  96.         pMap->DeleteTemp();
  97. }
  98.  
  99. CDC* PASCAL CDC::FromHandle(HDC hDC)
  100. {
  101.     CHandleMap* pMap = afxMapHDC(TRUE); //create map if not exist
  102.     ASSERT(pMap != NULL);
  103.     CDC* pDC = (CDC*)pMap->FromHandle(hDC);
  104.     ASSERT(pDC == NULL || pDC->m_hDC == hDC);
  105.     return pDC;
  106. }
  107.  
  108. BOOL CDC::Attach(HDC hDC)
  109. {
  110.     ASSERT(m_hDC == NULL);      // only attach once, detach on destroy
  111.     ASSERT(m_hAttribDC == NULL);    // only attach to an empty DC
  112.  
  113.     if (hDC == NULL)
  114.         return FALSE;
  115.     CHandleMap* pMap = afxMapHDC(TRUE); // create map if not exist
  116.     ASSERT(pMap != NULL);
  117.     pMap->SetPermanent(m_hDC = hDC, this);
  118.  
  119.     SetAttribDC(m_hDC);     // Default to same as output
  120.     return TRUE;
  121. }
  122.  
  123. HDC CDC::Detach()
  124. {
  125.     HDC hDC = m_hDC;
  126.     if (hDC != NULL)
  127.     {
  128.         CHandleMap* pMap = afxMapHDC(); // don't create if not exist
  129.         if (pMap != NULL)
  130.             pMap->RemoveHandle(m_hDC);
  131.     }
  132.  
  133.     ReleaseAttribDC();
  134.     m_hDC = NULL;
  135.     return hDC;
  136. }
  137.  
  138. BOOL CDC::DeleteDC()
  139. {
  140.     if (m_hDC == NULL)
  141.         return FALSE;
  142.  
  143.     return ::DeleteDC(Detach());
  144. }
  145.  
  146. CDC::~CDC()
  147. {
  148.     if (m_hDC != NULL)
  149.         ::DeleteDC(Detach());
  150. }
  151.  
  152.  
  153. void CDC::SetAttribDC(HDC hDC)  // Set the Attribute DC
  154. {
  155.     m_hAttribDC = hDC;
  156. }
  157.  
  158. void CDC::SetOutputDC(HDC hDC)  // Set the Output DC
  159. {
  160. #ifdef _DEBUG
  161.     CHandleMap* pMap = afxMapHDC();
  162.     if (pMap != NULL && pMap->LookupPermanent(m_hDC) == this)
  163.     {
  164.         TRACE0("Cannot Set Output hDC on Attached CDC.\n");
  165.         ASSERT(FALSE);
  166.     }
  167. #endif
  168.     m_hDC = hDC;
  169. }
  170.  
  171. void CDC::ReleaseAttribDC()     // Release the Attribute DC
  172. {
  173.     m_hAttribDC = NULL;
  174. }
  175.  
  176. void CDC::ReleaseOutputDC()     // Release the Output DC
  177. {
  178. #ifdef _DEBUG
  179.     CHandleMap* pMap = afxMapHDC();
  180.     if (pMap != NULL && pMap->LookupPermanent(m_hDC) == this)
  181.     {
  182.         TRACE0("Cannot Release Output hDC on Attached CDC.\n");
  183.         ASSERT(FALSE);
  184.     }
  185. #endif
  186.     m_hDC = NULL;
  187. }
  188.  
  189. /////////////////////////////////////////////////////////////////////////////
  190. // Out-of-line routines
  191.  
  192. int CDC::StartDoc(LPCTSTR lpszDocName)
  193. {
  194.     DOCINFO di;
  195.     memset(&di, 0, sizeof(DOCINFO));
  196.     di.cbSize = sizeof(DOCINFO);
  197.     di.lpszDocName = lpszDocName;
  198.     return StartDoc(&di);
  199. }
  200.  
  201. int CDC::SaveDC()
  202. {
  203.     ASSERT(m_hDC != NULL);
  204.     int nRetVal;
  205.     if (m_hAttribDC != NULL)
  206.         nRetVal = ::SaveDC(m_hAttribDC);
  207.     if (m_hDC != m_hAttribDC && ::SaveDC(m_hDC) != 0)
  208.         nRetVal = -1;   // -1 is the only valid restore value for complex DCs
  209.     return nRetVal;
  210. }
  211.  
  212. BOOL CDC::RestoreDC(int nSavedDC)
  213. {
  214.     // if two distinct DCs, nSavedDC can only be -1
  215.     ASSERT(m_hDC != NULL);
  216.     ASSERT(m_hDC == m_hAttribDC || nSavedDC == -1);
  217.  
  218.     BOOL bRetVal = TRUE;
  219.     if (m_hDC != m_hAttribDC)
  220.         bRetVal = ::RestoreDC(m_hDC, nSavedDC);
  221.     if (m_hAttribDC != NULL)
  222.         bRetVal = (bRetVal && ::RestoreDC(m_hAttribDC, nSavedDC));
  223.     return bRetVal;
  224. }
  225.  
  226. CGdiObject* PASCAL CDC::SelectGdiObject(HDC hDC, HGDIOBJ h)
  227. {
  228.     return CGdiObject::FromHandle(::SelectObject(hDC, h));
  229. }
  230.  
  231. CGdiObject* CDC::SelectStockObject(int nIndex)
  232. {
  233.     ASSERT(m_hDC != NULL);
  234.  
  235.     HGDIOBJ hObject = ::GetStockObject(nIndex);
  236.     HGDIOBJ hOldObj;
  237.  
  238.     ASSERT(hObject != NULL);
  239.     if (m_hDC != m_hAttribDC)
  240.         hOldObj = ::SelectObject(m_hDC, hObject);
  241.     if (m_hAttribDC != NULL)
  242.         hOldObj = ::SelectObject(m_hAttribDC, hObject);
  243.     return CGdiObject::FromHandle(hOldObj);
  244. }
  245.  
  246. CPen* CDC::SelectObject(CPen* pPen)
  247. {
  248.     ASSERT(m_hDC != NULL);
  249.     HGDIOBJ hOldObj;
  250.     if (m_hDC != m_hAttribDC)
  251.         hOldObj = ::SelectObject(m_hDC, pPen->GetSafeHandle());
  252.     if (m_hAttribDC != NULL)
  253.         hOldObj = ::SelectObject(m_hAttribDC, pPen->GetSafeHandle());
  254.     return (CPen*)CGdiObject::FromHandle(hOldObj);
  255. }
  256.  
  257. CBrush* CDC::SelectObject(CBrush* pBrush)
  258. {
  259.     ASSERT(m_hDC != NULL);
  260.     HGDIOBJ hOldObj;
  261.     if (m_hDC != m_hAttribDC)
  262.         hOldObj = ::SelectObject(m_hDC, pBrush->GetSafeHandle());
  263.     if (m_hAttribDC != NULL)
  264.         hOldObj = ::SelectObject(m_hAttribDC, pBrush->GetSafeHandle());
  265.     return (CBrush*)CGdiObject::FromHandle(hOldObj);
  266. }
  267.  
  268. CFont* CDC::SelectObject(CFont* pFont)
  269. {
  270.     ASSERT(m_hDC != NULL);
  271.     HGDIOBJ hOldObj;
  272.     if (m_hDC != m_hAttribDC)
  273.         hOldObj = ::SelectObject(m_hDC, pFont->GetSafeHandle());
  274.     if (m_hAttribDC != NULL)
  275.         hOldObj = ::SelectObject(m_hAttribDC, pFont->GetSafeHandle());
  276.     return (CFont*)CGdiObject::FromHandle(hOldObj);
  277. }
  278.  
  279. int CDC::SelectObject(CRgn* pRgn)
  280. {
  281.     ASSERT(m_hDC != NULL);
  282.     int nRetVal;
  283.     if (m_hDC != m_hAttribDC)
  284.         nRetVal = (int)::SelectObject(m_hDC, pRgn->GetSafeHandle());
  285.     if (m_hAttribDC != NULL)
  286.         nRetVal = (int)::SelectObject(m_hAttribDC, pRgn->GetSafeHandle());
  287.     return nRetVal;
  288. }
  289.  
  290. CPalette* CDC::SelectPalette(CPalette* pPalette, BOOL bForceBackground)
  291. {
  292.     ASSERT(m_hDC != NULL);
  293.  
  294.     return (CPalette*) CGdiObject::FromHandle(::SelectPalette(m_hDC,
  295.         (HPALETTE)pPalette->GetSafeHandle(), bForceBackground));
  296. }
  297.  
  298. COLORREF CDC::SetBkColor(COLORREF crColor)
  299. {
  300.     ASSERT(m_hDC != NULL);
  301.     COLORREF crRetVal;
  302.     if (m_hDC != m_hAttribDC)
  303.         crRetVal = ::SetBkColor(m_hDC, crColor);
  304.     if (m_hAttribDC != NULL)
  305.         crRetVal = ::SetBkColor(m_hAttribDC, crColor);
  306.     return crRetVal;
  307. }
  308.  
  309. int CDC::SetBkMode(int nBkMode)
  310. {
  311.     ASSERT(m_hDC != NULL);
  312.     int nRetVal;
  313.     if (m_hDC != m_hAttribDC)
  314.         nRetVal = ::SetBkMode(m_hDC, nBkMode);
  315.     if (m_hAttribDC != NULL)
  316.         nRetVal = ::SetBkMode(m_hAttribDC, nBkMode);
  317.     return nRetVal;
  318. }
  319.  
  320. int CDC::SetPolyFillMode(int nPolyFillMode)
  321. {
  322.     ASSERT(m_hDC != NULL);
  323.     int nRetVal;
  324.     if (m_hDC != m_hAttribDC)
  325.         nRetVal = ::SetPolyFillMode(m_hDC, nPolyFillMode);
  326.     if (m_hAttribDC != NULL)
  327.         nRetVal = ::SetPolyFillMode(m_hAttribDC, nPolyFillMode);
  328.     return nRetVal;
  329. }
  330.  
  331. int CDC::SetROP2(int nDrawMode)
  332. {
  333.     ASSERT(m_hDC != NULL);
  334.     int nRetVal;
  335.     if (m_hDC != m_hAttribDC)
  336.         nRetVal = ::SetROP2(m_hDC, nDrawMode);
  337.     if (m_hAttribDC != NULL)
  338.         nRetVal = ::SetROP2(m_hAttribDC, nDrawMode);
  339.     return nRetVal;
  340. }
  341.  
  342. int CDC::SetStretchBltMode(int nStretchMode)
  343. {
  344.     ASSERT(m_hDC != NULL);
  345.     int nRetVal;
  346.     if (m_hDC != m_hAttribDC)
  347.         nRetVal = ::SetStretchBltMode(m_hDC, nStretchMode);
  348.     if (m_hAttribDC != NULL)
  349.         nRetVal = ::SetStretchBltMode(m_hAttribDC, nStretchMode);
  350.     return nRetVal;
  351. }
  352.  
  353. COLORREF CDC::SetTextColor(COLORREF crColor)
  354. {
  355.     ASSERT(m_hDC != NULL);
  356.     COLORREF crRetVal;
  357.     if (m_hDC != m_hAttribDC)
  358.         crRetVal = ::SetTextColor(m_hDC, crColor);
  359.     if (m_hAttribDC != NULL)
  360.         crRetVal = ::SetTextColor(m_hAttribDC, crColor);
  361.     return crRetVal;
  362. }
  363.  
  364. int CDC::SetMapMode(int nMapMode)
  365. {
  366.     ASSERT(m_hDC != NULL);
  367.     int nRetVal;
  368.     if (m_hDC != m_hAttribDC)
  369.         nRetVal = ::SetMapMode(m_hDC, nMapMode);
  370.     if (m_hAttribDC != NULL)
  371.         nRetVal = ::SetMapMode(m_hAttribDC, nMapMode);
  372.     return nRetVal;
  373. }
  374.  
  375. CPoint CDC::SetViewportOrg(int x, int y)
  376. {
  377.     ASSERT(m_hDC != NULL);
  378.     POINT point;
  379.     if (m_hDC != m_hAttribDC)
  380.         VERIFY(::SetViewportOrgEx(m_hDC, x, y, &point));
  381.     if (m_hAttribDC != NULL)
  382.         VERIFY(::SetViewportOrgEx(m_hAttribDC, x, y, &point));
  383.     return point;
  384. }
  385.  
  386. CPoint CDC::OffsetViewportOrg(int nWidth, int nHeight)
  387. {
  388.     ASSERT(m_hDC != NULL);
  389.     POINT point;
  390.     if (m_hDC != m_hAttribDC)
  391.         VERIFY(::OffsetViewportOrgEx(m_hDC, nWidth, nHeight, &point));
  392.     if (m_hAttribDC != NULL)
  393.         VERIFY(::OffsetViewportOrgEx(m_hAttribDC, nWidth, nHeight, &point));
  394.     return point;
  395. }
  396.  
  397. CSize CDC::SetViewportExt(int x, int y)
  398. {
  399.     ASSERT(m_hDC != NULL);
  400.     SIZE size;
  401.     if (m_hDC != m_hAttribDC)
  402.         VERIFY(::SetViewportExtEx(m_hDC, x, y, &size));
  403.     if (m_hAttribDC != NULL)
  404.         VERIFY(::SetViewportExtEx(m_hAttribDC, x, y, &size));
  405.     return size;
  406. }
  407.  
  408. CSize CDC::ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom)
  409. {
  410.     ASSERT(m_hDC != NULL);
  411.     SIZE size;
  412.     if (m_hDC != m_hAttribDC)
  413.         VERIFY(::ScaleViewportExtEx(m_hDC, xNum, xDenom, yNum, yDenom, &size));
  414.     if (m_hAttribDC != NULL)
  415.         VERIFY(::ScaleViewportExtEx(m_hAttribDC, xNum, xDenom, yNum, yDenom, &size));
  416.     return size;
  417. }
  418.  
  419. CPoint CDC::SetWindowOrg(int x, int y)
  420. {
  421.     ASSERT(m_hDC != NULL);
  422.     POINT point;
  423.     if (m_hDC != m_hAttribDC)
  424.         VERIFY(::SetWindowOrgEx(m_hDC, x, y, &point));
  425.     if (m_hAttribDC != NULL)
  426.         VERIFY(::SetWindowOrgEx(m_hAttribDC, x, y, &point));
  427.     return point;
  428. }
  429.  
  430. CPoint CDC::OffsetWindowOrg(int nWidth, int nHeight)
  431. {
  432.     ASSERT(m_hDC != NULL);
  433.     POINT point;
  434.     if (m_hDC != m_hAttribDC)
  435.         VERIFY(::OffsetWindowOrgEx(m_hDC, nWidth, nHeight, &point));
  436.     if (m_hAttribDC != NULL)
  437.         VERIFY(::OffsetWindowOrgEx(m_hAttribDC, nWidth, nHeight, &point));
  438.     return point;
  439. }
  440.  
  441. CSize CDC::SetWindowExt(int x, int y)
  442. {
  443.     ASSERT(m_hDC != NULL);
  444.     SIZE size;
  445.     if (m_hDC != m_hAttribDC)
  446.         VERIFY(::SetWindowExtEx(m_hDC, x, y, &size));
  447.     if (m_hAttribDC != NULL)
  448.         VERIFY(::SetWindowExtEx(m_hAttribDC, x, y, &size));
  449.     return size;
  450. }
  451.  
  452. CSize CDC::ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom)
  453. {
  454.     ASSERT(m_hDC != NULL);
  455.     SIZE size;
  456.     if (m_hDC != m_hAttribDC)
  457.         VERIFY(::ScaleWindowExtEx(m_hDC, xNum, xDenom, yNum, yDenom, &size));
  458.     if (m_hAttribDC != NULL)
  459.         VERIFY(::ScaleWindowExtEx(m_hAttribDC, xNum, xDenom, yNum, yDenom, &size));
  460.     return size;
  461. }
  462.  
  463. int CDC::GetClipBox(LPRECT lpRect) const
  464. {
  465.     ASSERT(m_hDC != NULL);
  466.     return ::GetClipBox(m_hDC, lpRect);
  467. }
  468.  
  469. int CDC::SelectClipRgn(CRgn* pRgn)
  470. {
  471.     ASSERT(m_hDC != NULL);
  472.     int nRetVal;
  473.     if (m_hDC != m_hAttribDC)
  474.         nRetVal = ::SelectClipRgn(m_hDC, (HRGN)pRgn->GetSafeHandle());
  475.     if (m_hAttribDC != NULL)
  476.         nRetVal = ::SelectClipRgn(m_hAttribDC, (HRGN)pRgn->GetSafeHandle());
  477.     return nRetVal;
  478. }
  479.  
  480. int CDC::ExcludeClipRect(int x1, int y1, int x2, int y2)
  481. {
  482.     ASSERT(m_hDC != NULL);
  483.     int nRetVal;
  484.     if (m_hDC != m_hAttribDC)
  485.         nRetVal = ::ExcludeClipRect(m_hDC, x1, y1, x2, y2);
  486.     if (m_hAttribDC != NULL)
  487.         nRetVal = ::ExcludeClipRect(m_hAttribDC, x1, y1, x2, y2);
  488.     return nRetVal;
  489. }
  490.  
  491. int CDC::ExcludeClipRect(LPCRECT lpRect)
  492. {
  493.     ASSERT(m_hDC != NULL);
  494.     int nRetVal;
  495.     if (m_hDC != m_hAttribDC)
  496.         nRetVal = ::ExcludeClipRect(m_hDC, lpRect->left, lpRect->top,
  497.             lpRect->right, lpRect->bottom);
  498.     if (m_hAttribDC != NULL)
  499.         nRetVal = ::ExcludeClipRect(m_hAttribDC, lpRect->left, lpRect->top,
  500.             lpRect->right, lpRect->bottom);
  501.     return nRetVal;
  502. }
  503.  
  504. int CDC::IntersectClipRect(int x1, int y1, int x2, int y2)
  505. {
  506.     ASSERT(m_hDC != NULL);
  507.     int nRetVal;
  508.     if (m_hDC != m_hAttribDC)
  509.         nRetVal = ::IntersectClipRect(m_hDC, x1, y1, x2, y2);
  510.     if (m_hAttribDC != NULL)
  511.         nRetVal = ::IntersectClipRect(m_hAttribDC, x1, y1, x2, y2);
  512.     return nRetVal;
  513. }
  514.  
  515. int CDC::IntersectClipRect(LPCRECT lpRect)
  516. {
  517.     ASSERT(m_hDC != NULL);
  518.     int nRetVal;
  519.     if (m_hDC != m_hAttribDC)
  520.         nRetVal = ::IntersectClipRect(m_hDC, lpRect->left, lpRect->top,
  521.             lpRect->right, lpRect->bottom);
  522.     if (m_hAttribDC != NULL)
  523.         nRetVal = ::IntersectClipRect(m_hAttribDC, lpRect->left, lpRect->top,
  524.             lpRect->right, lpRect->bottom);
  525.     return nRetVal;
  526. }
  527.  
  528. int CDC::OffsetClipRgn(int x, int y)
  529. {
  530.     ASSERT(m_hDC != NULL);
  531.     int nRetVal;
  532.     if (m_hDC != m_hAttribDC)
  533.         nRetVal = ::OffsetClipRgn(m_hDC, x, y);
  534.     if (m_hAttribDC != NULL)
  535.         nRetVal = ::OffsetClipRgn(m_hAttribDC, x, y);
  536.     return nRetVal;
  537. }
  538.  
  539. int CDC::OffsetClipRgn(SIZE size)
  540. {
  541.     ASSERT(m_hDC != NULL);
  542.     int nRetVal;
  543.     if (m_hDC != m_hAttribDC)
  544.         nRetVal = ::OffsetClipRgn(m_hDC, size.cx, size.cy);
  545.     if (m_hAttribDC != NULL)
  546.         nRetVal = ::OffsetClipRgn(m_hAttribDC, size.cx, size.cy);
  547.     return nRetVal;
  548. }
  549.  
  550. CPoint CDC::MoveTo(int x, int y)
  551. {
  552.     ASSERT(m_hDC != NULL);
  553.     POINT point;
  554.     if (m_hDC != m_hAttribDC)
  555.         VERIFY(::MoveToEx(m_hDC, x, y, &point));
  556.     if (m_hAttribDC != NULL)
  557.         VERIFY(::MoveToEx(m_hAttribDC, x, y, &point));
  558.     return point;
  559. }
  560.  
  561. BOOL CDC::LineTo(int x, int y)
  562. {
  563.     ASSERT(m_hDC != NULL);
  564.     if (m_hAttribDC != NULL && m_hDC != m_hAttribDC)
  565.         ::MoveToEx(m_hAttribDC, x, y, NULL);
  566.     return ::LineTo(m_hDC, x, y);
  567. }
  568.  
  569. UINT CDC::SetTextAlign(UINT nFlags)
  570. {
  571.     ASSERT(m_hDC != NULL);
  572.     UINT nRetVal;
  573.     if (m_hDC != m_hAttribDC)
  574.         ::SetTextAlign(m_hDC, nFlags);
  575.     if (m_hAttribDC != NULL)
  576.         nRetVal = ::SetTextAlign(m_hAttribDC, nFlags);
  577.     return nRetVal;
  578. }
  579.  
  580. #ifndef _MAC
  581. int CDC::SetTextJustification(int nBreakExtra, int nBreakCount)
  582. {
  583.     ASSERT(m_hDC != NULL);
  584.     int nRetVal;
  585.     if (m_hDC != m_hAttribDC)
  586.         nRetVal = ::SetTextJustification(m_hDC, nBreakExtra, nBreakCount);
  587.     if (m_hAttribDC != NULL)
  588.         nRetVal = ::SetTextJustification(m_hAttribDC, nBreakExtra, nBreakCount);
  589.     return nRetVal;
  590. }
  591. #endif
  592.  
  593. int CDC::SetTextCharacterExtra(int nCharExtra)
  594. {
  595.     ASSERT(m_hDC != NULL);
  596.     int nRetVal;
  597.     if (m_hDC != m_hAttribDC)
  598.         nRetVal = ::SetTextCharacterExtra(m_hDC, nCharExtra);
  599.     if (m_hAttribDC != NULL)
  600.         nRetVal = ::SetTextCharacterExtra(m_hAttribDC, nCharExtra);
  601.     return nRetVal;
  602. }
  603.  
  604. DWORD CDC::SetMapperFlags(DWORD dwFlag)
  605. {
  606.     ASSERT(m_hDC != NULL);
  607.     DWORD dwRetVal;
  608.     if (m_hDC != m_hAttribDC)
  609.         dwRetVal = ::SetMapperFlags(m_hDC, dwFlag);
  610.     if (m_hAttribDC != NULL)
  611.         dwRetVal = ::SetMapperFlags(m_hAttribDC, dwFlag);
  612.     return dwRetVal;
  613. }
  614.  
  615. /////////////////////////////////////////////////////////////////////////////
  616. // Advanced Win32 GDI functions
  617.  
  618. #ifndef _MAC
  619. BOOL CDC::ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
  620. {
  621.     ASSERT(m_hDC != NULL);
  622.     BOOL bResult = ::ArcTo(m_hDC, x1, y1, x2, y2, x3, y3, x4, y4);
  623.     if (m_hDC != m_hAttribDC)
  624.     {
  625.         CPoint pt;
  626.         VERIFY(::GetCurrentPositionEx(m_hDC, &pt));
  627.         VERIFY(::MoveToEx(m_hAttribDC, pt.x, pt.y, NULL));
  628.     }
  629.     return bResult;
  630. }
  631.  
  632. int CDC::SetArcDirection(int nArcDirection)
  633. {
  634.     ASSERT(m_hDC != NULL);
  635.     int nResult;
  636.     if (m_hDC != m_hAttribDC)
  637.         nResult = ::SetArcDirection(m_hDC, nArcDirection);
  638.     if (m_hAttribDC != NULL)
  639.         nResult = ::SetArcDirection(m_hAttribDC, nArcDirection);
  640.     return nResult;
  641. }
  642.  
  643. BOOL CDC::PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount)
  644. {
  645.     ASSERT(m_hDC != NULL);
  646.     BOOL bResult = ::PolyDraw(m_hDC, lpPoints, lpTypes, nCount);
  647.     if (m_hDC != m_hAttribDC)
  648.     {
  649.         CPoint pt;
  650.         VERIFY(::GetCurrentPositionEx(m_hDC, &pt));
  651.         VERIFY(::MoveToEx(m_hAttribDC, pt.x, pt.y, NULL));
  652.     }
  653.     return bResult;
  654. }
  655.  
  656. BOOL CDC::PolylineTo(const POINT* lpPoints, int nCount)
  657. {
  658.     ASSERT(m_hDC != NULL);
  659.     BOOL bResult = ::PolylineTo(m_hDC, lpPoints, nCount);
  660.     if (m_hDC != m_hAttribDC)
  661.     {
  662.         CPoint pt;
  663.         VERIFY(::GetCurrentPositionEx(m_hDC, &pt));
  664.         VERIFY(::MoveToEx(m_hAttribDC, pt.x, pt.y, NULL));
  665.     }
  666.     return bResult;
  667. }
  668.  
  669. BOOL CDC::SetColorAdjustment(const COLORADJUSTMENT* lpColorAdjust)
  670. {
  671.     ASSERT(m_hDC != NULL);
  672.     BOOL bResult;
  673.     if (m_hDC != m_hAttribDC)
  674.         bResult = ::SetColorAdjustment(m_hDC, lpColorAdjust);
  675.     if (m_hAttribDC != NULL)
  676.         bResult = ::SetColorAdjustment(m_hAttribDC, lpColorAdjust);
  677.     return bResult;
  678. }
  679.  
  680. BOOL CDC::PolyBezierTo(const POINT* lpPoints, int nCount)
  681. {
  682.     ASSERT(m_hDC != NULL);
  683.     BOOL bResult = ::PolyBezierTo(m_hDC, lpPoints, nCount);
  684.     if (m_hDC != m_hAttribDC)
  685.     {
  686.         CPoint pt;
  687.         VERIFY(::GetCurrentPositionEx(m_hDC, &pt));
  688.         VERIFY(::MoveToEx(m_hAttribDC, pt.x, pt.y, NULL));
  689.     }
  690.     return bResult;
  691. }
  692.  
  693. BOOL CDC::SelectClipPath(int nMode)
  694. {
  695.     ASSERT(m_hDC != NULL);
  696.  
  697.     // output DC always holds the current path
  698.     if (!::SelectClipPath(m_hDC, nMode))
  699.         return FALSE;
  700.  
  701.     // transfer clipping region into the attribute DC
  702.     BOOL bResult = TRUE;
  703.     if (m_hDC != m_hAttribDC)
  704.     {
  705.         HRGN hRgn = ::CreateRectRgn(0, 0, 0, 0);
  706.         if (::GetClipRgn(m_hDC, hRgn) < 0 || !::SelectClipRgn(m_hAttribDC, hRgn))
  707.         {
  708.             TRACE0("Error: unable to transfer clip region in CDC::SelectClipPath!\n");
  709.             bResult = FALSE;
  710.         }
  711.         DeleteObject(hRgn);
  712.     }
  713.     return bResult;
  714. }
  715.  
  716. int CDC::SelectClipRgn(CRgn* pRgn, int nMode)
  717. {
  718.     ASSERT(m_hDC != NULL);
  719.     int nRetVal;
  720.     if (m_hDC != m_hAttribDC)
  721.         nRetVal = ::ExtSelectClipRgn(m_hDC, (HRGN)pRgn->GetSafeHandle(), nMode);
  722.     if (m_hAttribDC != NULL)
  723.         nRetVal = ::ExtSelectClipRgn(m_hAttribDC, (HRGN)pRgn->GetSafeHandle(), nMode);
  724.     return nRetVal;
  725. }
  726. #endif //!_MAC
  727.  
  728. /////////////////////////////////////////////////////////////////////////////
  729. // Special handling for metafile playback
  730.  
  731. int CALLBACK AfxEnumMetaFileProc(HDC hDC,
  732.     HANDLETABLE* pHandleTable, METARECORD* pMetaRec, int nHandles, LPARAM lParam)
  733. {
  734.     CDC* pDC = (CDC*)lParam;
  735.     ASSERT_VALID(pDC);
  736.  
  737.     switch (pMetaRec->rdFunction)
  738.     {
  739.     // these records have effects different for each CDC derived class
  740.     case META_SETMAPMODE:
  741.         pDC->SetMapMode((int)(short)pMetaRec->rdParm[0]);
  742.         break;
  743.     case META_SETWINDOWEXT:
  744.         pDC->SetWindowExt(
  745.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  746.         break;
  747.     case META_SETWINDOWORG:
  748.         pDC->SetWindowOrg(
  749.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  750.         break;
  751.     case META_SETVIEWPORTEXT:
  752.         pDC->SetViewportExt(
  753.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  754.         break;
  755.     case META_SETVIEWPORTORG:
  756.         pDC->SetViewportOrg(
  757.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  758.         break;
  759.     case META_SCALEWINDOWEXT:
  760.         pDC->ScaleWindowExt(
  761.             (int)(short)pMetaRec->rdParm[3], (int)(short)pMetaRec->rdParm[2],
  762.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  763.         break;
  764.     case META_SCALEVIEWPORTEXT:
  765.         pDC->ScaleViewportExt(
  766.             (int)(short)pMetaRec->rdParm[3], (int)(short)pMetaRec->rdParm[2],
  767.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  768.         break;
  769.     case META_OFFSETVIEWPORTORG:
  770.         pDC->OffsetViewportOrg(
  771.             (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
  772.         break;
  773.     case META_SAVEDC:
  774.         pDC->SaveDC();
  775.         break;
  776.     case META_RESTOREDC:
  777.         pDC->RestoreDC((int)(short)pMetaRec->rdParm[0]);
  778.         break;
  779.     case META_SETBKCOLOR:
  780.         pDC->SetBkColor(*(UNALIGNED COLORREF*)&pMetaRec->rdParm[0]);
  781.         break;
  782.     case META_SETTEXTCOLOR:
  783.         pDC->SetTextColor(*(UNALIGNED COLORREF*)&pMetaRec->rdParm[0]);
  784.         break;
  785.  
  786.     // need to watch out for SelectObject(HFONT), for custom font mapping
  787.     case META_SELECTOBJECT:
  788.         {
  789.             HGDIOBJ hObject = pHandleTable->objectHandle[pMetaRec->rdParm[0]];
  790.             UINT nObjType = GetObjectType(hObject);
  791.             if (nObjType == 0)
  792.             {
  793.                 // object type is unknown, determine if it is a font
  794.                 HFONT hStockFont = (HFONT)::GetStockObject(SYSTEM_FONT);
  795.                 HFONT hFontOld = (HFONT)::SelectObject(pDC->m_hDC, hStockFont);
  796.                 HGDIOBJ hObjOld = ::SelectObject(pDC->m_hDC, hObject);
  797.                 if (hObjOld == hStockFont)
  798.                 {
  799.                     // got the stock object back, so must be selecting a font
  800.                     pDC->SelectObject(CFont::FromHandle((HFONT)hObject));
  801.                     break;  // don't play the default record
  802.                 }
  803.                 else
  804.                 {
  805.                     // didn't get the stock object back, so restore everything
  806.                     ::SelectObject(pDC->m_hDC, hFontOld);
  807.                     ::SelectObject(pDC->m_hDC, hObjOld);
  808.                 }
  809.                 // and fall through to PlayMetaFileRecord...
  810.             }
  811.             else if (nObjType == OBJ_FONT)
  812.             {
  813.                 // play back as CDC::SelectObject(CFont*)
  814.                 pDC->SelectObject(CFont::FromHandle((HFONT)hObject));
  815.                 break;  // don't play the default record
  816.             }
  817.         }
  818.         // fall through...
  819.  
  820.     default:
  821.         ::PlayMetaFileRecord(hDC, pHandleTable, pMetaRec, nHandles);
  822.         break;
  823.     }
  824.  
  825.     return 1;
  826. }
  827.  
  828. BOOL CDC::PlayMetaFile(HMETAFILE hMF)
  829. {
  830.     if (::GetDeviceCaps(m_hDC, TECHNOLOGY) == DT_METAFILE)
  831.     {
  832.         // playing metafile in metafile, just use core windows API
  833.         return ::PlayMetaFile(m_hDC, hMF);
  834.     }
  835.  
  836.     // for special playback, lParam == pDC
  837.     return ::EnumMetaFile(m_hDC, hMF, AfxEnumMetaFileProc, (LPARAM)this);
  838. }
  839.  
  840. /////////////////////////////////////////////////////////////////////////////
  841. // Coordinate transforms
  842.  
  843. void CDC::LPtoDP(LPSIZE lpSize) const
  844. {
  845.     ASSERT(AfxIsValidAddress(lpSize, sizeof(SIZE)));
  846.  
  847.     CSize sizeWinExt = GetWindowExt();
  848.     CSize sizeVpExt = GetViewportExt();
  849.     lpSize->cx = MulDiv(lpSize->cx, abs(sizeVpExt.cx), abs(sizeWinExt.cx));
  850.     lpSize->cy = MulDiv(lpSize->cy, abs(sizeVpExt.cy), abs(sizeWinExt.cy));
  851. }
  852.  
  853. void CDC::DPtoLP(LPSIZE lpSize) const
  854. {
  855.     ASSERT(AfxIsValidAddress(lpSize, sizeof(SIZE)));
  856.  
  857.     CSize sizeWinExt = GetWindowExt();
  858.     CSize sizeVpExt = GetViewportExt();
  859.     lpSize->cx = MulDiv(lpSize->cx, abs(sizeWinExt.cx), abs(sizeVpExt.cx));
  860.     lpSize->cy = MulDiv(lpSize->cy, abs(sizeWinExt.cy), abs(sizeVpExt.cy));
  861. }
  862.  
  863. /////////////////////////////////////////////////////////////////////////////
  864. // Helper DCs
  865.  
  866. #ifdef _DEBUG
  867. void CClientDC::AssertValid() const
  868. {
  869.     CDC::AssertValid();
  870.     ASSERT(m_hWnd == NULL || ::IsWindow(m_hWnd));
  871. }
  872.  
  873. void CClientDC::Dump(CDumpContext& dc) const
  874. {
  875.     CDC::Dump(dc);
  876.  
  877.     dc << "m_hWnd = " << (UINT)m_hWnd;
  878.     dc << "\n";
  879. }
  880. #endif
  881.  
  882. CClientDC::CClientDC(CWnd* pWnd)
  883. {
  884.     ASSERT(pWnd == NULL || ::IsWindow(pWnd->m_hWnd));
  885.  
  886.     if (!Attach(::GetDC(m_hWnd = pWnd->GetSafeHwnd())))
  887.         AfxThrowResourceException();
  888. }
  889.  
  890. CClientDC::~CClientDC()
  891. {
  892.     ASSERT(m_hDC != NULL);
  893.     ::ReleaseDC(m_hWnd, Detach());
  894. }
  895.  
  896. #ifdef _DEBUG
  897. void CWindowDC::AssertValid() const
  898. {
  899.     CDC::AssertValid();
  900.     ASSERT(m_hWnd == NULL || ::IsWindow(m_hWnd));
  901. }
  902.  
  903. void CWindowDC::Dump(CDumpContext& dc) const
  904. {
  905.     CDC::Dump(dc);
  906.  
  907.     dc << "m_hWnd = " << (UINT)m_hWnd;
  908.     dc << "\n";
  909. }
  910. #endif
  911.  
  912. CWindowDC::CWindowDC(CWnd* pWnd)
  913. {
  914.     ASSERT(pWnd == NULL || ::IsWindow(pWnd->m_hWnd));
  915.  
  916.     if (!Attach(::GetWindowDC(m_hWnd = pWnd->GetSafeHwnd())))
  917.         AfxThrowResourceException();
  918. }
  919.  
  920. CWindowDC::~CWindowDC()
  921. {
  922.     ASSERT(m_hDC != NULL);
  923.     ::ReleaseDC(m_hWnd, Detach());
  924. }
  925.  
  926. #ifdef _DEBUG
  927. void CPaintDC::AssertValid() const
  928. {
  929.     CDC::AssertValid();
  930.     ASSERT(::IsWindow(m_hWnd));
  931. }
  932.  
  933. void CPaintDC::Dump(CDumpContext& dc) const
  934. {
  935.     CDC::Dump(dc);
  936.  
  937.     dc << "m_hWnd = " << (UINT)m_hWnd;
  938.     dc << "\nm_ps.hdc = " << (UINT)m_ps.hdc;
  939.     dc << "\nm_ps.fErase = " << m_ps.fErase;
  940.     dc << "\nm_ps.rcPaint = " << (CRect)m_ps.rcPaint;
  941.  
  942.     dc << "\n";
  943. }
  944. #endif
  945.  
  946. CPaintDC::CPaintDC(CWnd* pWnd)
  947. {
  948.     ASSERT_VALID(pWnd);
  949.     ASSERT(::IsWindow(pWnd->m_hWnd));
  950.  
  951.     if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)))
  952.         AfxThrowResourceException();
  953. }
  954.  
  955. CPaintDC::~CPaintDC()
  956. {
  957.     ASSERT(m_hDC != NULL);
  958.     ASSERT(::IsWindow(m_hWnd));
  959.  
  960.     ::EndPaint(m_hWnd, &m_ps);
  961.     Detach();
  962. }
  963.  
  964. /////////////////////////////////////////////////////////////////////////////
  965. // CGdiObject
  966.  
  967. #ifdef _DEBUG
  968. void CGdiObject::Dump(CDumpContext& dc) const
  969. {
  970.     CObject::Dump(dc);
  971.  
  972.     dc << "m_hObject = " << (UINT)m_hObject;
  973.     dc << "\n";
  974. }
  975.  
  976. void CGdiObject::AssertValid() const
  977. {
  978.     CObject::AssertValid();
  979.     ASSERT(m_hObject == NULL ||
  980.         (afxData.bWin32s || ::GetObjectType(m_hObject) != 0));
  981. }
  982. #endif
  983.  
  984. static CHandleMap* afxMapHGDIOBJ(BOOL bCreate = FALSE);
  985.  
  986. static CHandleMap* afxMapHGDIOBJ(BOOL bCreate)
  987. {
  988.     AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
  989.     if (pState->m_pmapHGDIOBJ == NULL && bCreate)
  990.     {
  991.         BOOL bEnable = AfxEnableMemoryTracking(FALSE);
  992. #ifndef _AFX_PORTABLE
  993.         _PNH pnhOldHandler = AfxSetNewHandler(&AfxCriticalNewHandler);
  994. #endif
  995.         pState->m_pmapHGDIOBJ = new CHandleMap(RUNTIME_CLASS(CGdiObject),
  996.             offsetof(CGdiObject, m_hObject));
  997.  
  998. #ifndef _AFX_PORTABLE
  999.         AfxSetNewHandler(pnhOldHandler);
  1000. #endif
  1001.         AfxEnableMemoryTracking(bEnable);
  1002.     }
  1003.     return pState->m_pmapHGDIOBJ;
  1004. }
  1005.  
  1006. void PASCAL CGdiObject::DeleteTempMap()
  1007. {
  1008.     CHandleMap* pMap = afxMapHGDIOBJ();
  1009.     if (pMap != NULL)
  1010.         pMap->DeleteTemp();
  1011. }
  1012.  
  1013. CGdiObject* PASCAL CGdiObject::FromHandle(HGDIOBJ h)
  1014. {
  1015.     CHandleMap* pMap = afxMapHGDIOBJ(TRUE); //create map if not exist
  1016.     ASSERT(pMap != NULL);
  1017.     CGdiObject* pObject = (CGdiObject*)pMap->FromHandle(h);
  1018.     ASSERT(pObject == NULL || pObject->m_hObject == h);
  1019.     return pObject;
  1020. }
  1021.  
  1022. BOOL CGdiObject::Attach(HGDIOBJ hObject)
  1023. {
  1024.     ASSERT(m_hObject == NULL);      // only attach once, detach on destroy
  1025.     if (hObject == NULL)
  1026.         return FALSE;
  1027.     CHandleMap* pMap = afxMapHGDIOBJ(TRUE); // create map if not exist
  1028.     ASSERT(pMap != NULL);
  1029.     pMap->SetPermanent(m_hObject = hObject, this);
  1030.     return TRUE;
  1031. }
  1032.  
  1033. HGDIOBJ CGdiObject::Detach()
  1034. {
  1035.     HGDIOBJ hObject = m_hObject;
  1036.     if (hObject != NULL)
  1037.     {
  1038.         CHandleMap* pMap = afxMapHGDIOBJ(); // don't create if not exist
  1039.         if (pMap != NULL)
  1040.             pMap->RemoveHandle(m_hObject);
  1041.     }
  1042.  
  1043.     m_hObject = NULL;
  1044.     return hObject;
  1045. }
  1046.  
  1047. BOOL CGdiObject::DeleteObject()
  1048. {
  1049.     if (m_hObject == NULL)
  1050.         return FALSE;
  1051.     return ::DeleteObject(Detach());
  1052. }
  1053.  
  1054. /////////////////////////////////////////////////////////////////////////////
  1055. // Standard GDI objects
  1056.  
  1057. /////////////////////////////////////////////////////////////////////////////
  1058. // CPen
  1059.  
  1060. CPen::CPen(int nPenStyle, int nWidth, COLORREF crColor)
  1061. {
  1062.     if (!Attach(::CreatePen(nPenStyle, nWidth, crColor)))
  1063.         AfxThrowResourceException();
  1064. }
  1065.  
  1066. #ifndef _MAC
  1067. CPen::CPen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush,
  1068.     int nStyleCount, const DWORD* lpStyle)
  1069. {
  1070.     if (!Attach(::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount,
  1071.             lpStyle)))
  1072.         AfxThrowResourceException();
  1073. }
  1074. #endif
  1075.  
  1076. /////////////////////////////////////////////////////////////////////////////
  1077.  
  1078. #ifdef _DEBUG
  1079. void CPen::Dump(CDumpContext& dc) const
  1080. {
  1081.     CGdiObject::Dump(dc);
  1082.  
  1083.     if (m_hObject == NULL)
  1084.         return;
  1085.  
  1086.     if (!afxData.bWin32s && ::GetObjectType(m_hObject) != OBJ_PEN)
  1087.     {
  1088.         // not a valid object
  1089.         dc << "has ILLEGAL HPEN!";
  1090.         return;
  1091.     }
  1092.  
  1093.     LOGPEN lp;
  1094.     VERIFY(GetObject(sizeof(lp), &lp));
  1095.     dc << "lgpn.lopnStyle = " << lp.lopnStyle;
  1096.     dc << "\nlgpn.lopnWidth.x (width) = " << lp.lopnWidth.x;
  1097.     dc << "\nlgpn.lopnColor = " << (void*)lp.lopnColor;
  1098.  
  1099.     dc << "\n";
  1100. }
  1101. #endif
  1102.  
  1103. /////////////////////////////////////////////////////////////////////////////
  1104. // CBrush
  1105.  
  1106. CBrush::CBrush(COLORREF crColor)
  1107. {
  1108.     if (!Attach(::CreateSolidBrush(crColor)))
  1109.         AfxThrowResourceException();
  1110. }
  1111.  
  1112. CBrush::CBrush(int nIndex, COLORREF crColor)
  1113. {
  1114.     if (!Attach(::CreateHatchBrush(nIndex, crColor)))
  1115.         AfxThrowResourceException();
  1116. }
  1117.  
  1118. CBrush::CBrush(CBitmap* pBitmap)
  1119. {
  1120.     ASSERT_VALID(pBitmap);
  1121.  
  1122.     if (!Attach(::CreatePatternBrush((HBITMAP)pBitmap->m_hObject)))
  1123.         AfxThrowResourceException();
  1124. }
  1125.  
  1126. BOOL CBrush::CreateDIBPatternBrush(HGLOBAL hPackedDIB, UINT nUsage)
  1127. {
  1128.     ASSERT(hPackedDIB != NULL);
  1129.     const void* lpPackedDIB = ::GlobalLock(hPackedDIB);
  1130.     ASSERT(lpPackedDIB != NULL);
  1131.     BOOL bResult = Attach(::CreateDIBPatternBrushPt(lpPackedDIB, nUsage));
  1132.     ::GlobalUnlock(hPackedDIB);
  1133.     return bResult;
  1134. }
  1135.  
  1136. #ifdef _DEBUG
  1137. void CBrush::Dump(CDumpContext& dc) const
  1138. {
  1139.     CGdiObject::Dump(dc);
  1140.  
  1141.     if (m_hObject == NULL)
  1142.         return;
  1143.  
  1144.     if (!afxData.bWin32s && ::GetObjectType(m_hObject) != OBJ_BRUSH)
  1145.     {
  1146.         // not a valid window
  1147.         dc << "has ILLEGAL HBRUSH!";
  1148.         return;
  1149.     }
  1150.  
  1151.     LOGBRUSH lb;
  1152.     VERIFY(GetObject(sizeof(lb), &lb));
  1153.     dc << "lb.lbStyle = " << lb.lbStyle;
  1154.     dc << "\nlb.lbHatch = " << lb.lbHatch;
  1155.     dc << "\nlb.lbColor = " << (void*)lb.lbColor;
  1156.  
  1157.     dc << "\n";
  1158. }
  1159. #endif
  1160.  
  1161. /////////////////////////////////////////////////////////////////////////////
  1162.  
  1163. #ifdef _DEBUG
  1164. void CFont::Dump(CDumpContext& dc) const
  1165. {
  1166.     CGdiObject::Dump(dc);
  1167.  
  1168.     if (m_hObject == NULL)
  1169.         return;
  1170.  
  1171.     if (!afxData.bWin32s && ::GetObjectType(m_hObject) != OBJ_FONT)
  1172.     {
  1173.         // not a valid GDI object
  1174.         dc << "has ILLEGAL HFONT!";
  1175.         return;
  1176.     }
  1177.  
  1178.     LOGFONT lf;
  1179.     VERIFY(GetObject(sizeof(lf), &lf));
  1180.     dc << "lf.lfHeight = " << lf.lfHeight;
  1181.     dc << "\nlf.lfWidth = " << lf.lfWidth;
  1182.     dc << "\nlf.lfEscapement = " << lf.lfEscapement;
  1183.     dc << "\nlf.lfOrientation = " << lf.lfOrientation;
  1184.     dc << "\nlf.lfWeight = " << lf.lfWeight;
  1185.     dc << "\nlf.lfItalic = " << (int)lf.lfItalic;
  1186.     dc << "\nlf.lfUnderline = " << (int)lf.lfUnderline;
  1187.     dc << "\nlf.lfStrikeOut = " << (int)lf.lfStrikeOut;
  1188.     dc << "\nlf.lfCharSet = " << (int)lf.lfCharSet;
  1189.     dc << "\nlf.lfOutPrecision = " << (int)lf.lfOutPrecision;
  1190.     dc << "\nlf.lfClipPrecision = " << (int)lf.lfClipPrecision;
  1191.     dc << "\nlf.lfQuality = " << (int)lf.lfQuality;
  1192.     dc << "\nlf.lfPitchAndFamily = " << (int)lf.lfPitchAndFamily;
  1193.     dc << "\nlf.lfFaceName = " << (LPCTSTR)lf.lfFaceName;
  1194.  
  1195.     dc << "\n";
  1196. }
  1197. #endif
  1198.  
  1199. /////////////////////////////////////////////////////////////////////////////
  1200.  
  1201. #ifdef _DEBUG
  1202. void CBitmap::Dump(CDumpContext& dc) const
  1203. {
  1204.     CGdiObject::Dump(dc);
  1205.  
  1206.     if (m_hObject == NULL)
  1207.         return;
  1208.  
  1209.     if (!afxData.bWin32s && ::GetObjectType(m_hObject) != OBJ_BITMAP)
  1210.     {
  1211.         // not a valid object
  1212.         dc << "has ILLEGAL HBITMAP!";
  1213.         return;
  1214.     }
  1215.  
  1216.     BITMAP bm;
  1217.     VERIFY(GetObject(sizeof(bm), &bm));
  1218.     dc << "bm.bmType = " << bm.bmType;
  1219.     dc << "\nbm.bmHeight = " << bm.bmHeight;
  1220.     dc << "\nbm.bmWidth = " << bm.bmWidth;
  1221.     dc << "\nbm.bmWidthBytes = " << bm.bmWidthBytes;
  1222.     dc << "\nbm.bmPlanes = " << bm.bmPlanes;
  1223.     dc << "\nbm.bmBitsPixel = " << bm.bmBitsPixel;
  1224.  
  1225.     dc << "\n";
  1226. }
  1227. #endif
  1228.  
  1229. #ifdef AFX_INIT_SEG
  1230. #pragma code_seg(AFX_INIT_SEG)
  1231. #endif
  1232.  
  1233. IMPLEMENT_DYNAMIC(CResourceException, CException)
  1234. CResourceException _simpleResourceException(FALSE, AFX_IDS_RESOURCE_EXCEPTION);
  1235.  
  1236. IMPLEMENT_DYNAMIC(CUserException, CException)
  1237. CUserException _simpleUserException(FALSE, AFX_IDS_USER_EXCEPTION);
  1238.  
  1239. IMPLEMENT_DYNCREATE(CDC, CObject)
  1240. IMPLEMENT_DYNAMIC(CClientDC, CDC)
  1241. IMPLEMENT_DYNAMIC(CWindowDC, CDC)
  1242. IMPLEMENT_DYNAMIC(CPaintDC, CDC)
  1243. IMPLEMENT_DYNCREATE(CGdiObject, CObject)
  1244.  
  1245. IMPLEMENT_DYNAMIC(CPen, CGdiObject)
  1246. IMPLEMENT_DYNAMIC(CBrush, CGdiObject)
  1247. IMPLEMENT_DYNAMIC(CFont, CGdiObject)
  1248. IMPLEMENT_DYNAMIC(CBitmap, CGdiObject)
  1249. IMPLEMENT_DYNAMIC(CPalette, CGdiObject)
  1250. IMPLEMENT_DYNAMIC(CRgn, CGdiObject)
  1251.  
  1252. /////////////////////////////////////////////////////////////////////////////
  1253. // Standard exception processing
  1254.  
  1255. #ifdef AFX_CORE2_SEG
  1256. #pragma code_seg(AFX_CORE2_SEG)
  1257. #endif
  1258.  
  1259. // resource failure
  1260. void AFXAPI AfxThrowResourceException()
  1261. {
  1262.     THROW((CResourceException*)&_simpleResourceException);
  1263. }
  1264.  
  1265. // user alert
  1266. void AFXAPI AfxThrowUserException()
  1267. {
  1268.     THROW((CUserException*)&_simpleUserException);
  1269. }
  1270.  
  1271. #ifdef AFX_INIT_SEG
  1272. #pragma code_seg(AFX_INIT_SEG)
  1273. #endif
  1274.  
  1275. /////////////////////////////////////////////////////////////////////////////
  1276.