home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / OutlineMetric.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  1.8 KB  |  54 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : outlinetextmetric.h                                                 //
  12. //  Description: Wrapper for OUTLINETEXTMETRIC structure                             //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. class KOutlineTextMetric
  17. {
  18. public:
  19.     OUTLINETEXTMETRIC * m_pOtm;
  20.  
  21.     KOutlineTextMetric(HDC hDC)
  22.     {
  23.         int size = GetOutlineTextMetrics(hDC, 0, NULL);  // query size
  24.  
  25.         if ( size )
  26.         {
  27.             m_pOtm = (OUTLINETEXTMETRIC *) new BYTE[size];   // allocation
  28.             GetOutlineTextMetrics(hDC, size, m_pOtm);        // query data
  29.  
  30.             // make sure structure alignment is right, OUTLINETEXTMETIRC is 4-byte aligned
  31.             assert( (((unsigned) & m_pOtm->otmFiller - (unsigned) m_pOtm) %4) == 0);
  32.         }
  33.         else
  34.             m_pOtm = NULL;
  35.     }
  36.  
  37.     ~KOutlineTextMetric()
  38.     {
  39.         if ( m_pOtm )
  40.         {
  41.             delete [] (BYTE *) m_pOtm;
  42.             m_pOtm = NULL;
  43.         }
  44.     }
  45.  
  46.     const TCHAR * GetName(PSTR nOffset) const
  47.     {
  48.         if ( m_pOtm )
  49.             return (const TCHAR *) ((BYTE *) m_pOtm + (int) nOffset);
  50.         else
  51.             return NULL;
  52.     }
  53. };
  54.