home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_03 / Handles / GDI.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  2.0 KB  |  71 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : gdi.cpp                                                             //
  10. //  Description: GDI object implementation illustration, Chapter 3                   //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define  STRICT
  15. #define  WIN32_LEAN_AND_MEAN
  16. #include <windows.h>
  17. #include "gdi.h"
  18.  
  19. class _RealPen : public _Pen
  20. {
  21.     LOGPEN m_LogPen;
  22.  
  23. public:
  24.     _RealPen(int fnPenStyle, int nWidth, COLORREF crColor)
  25.     {
  26.         m_LogPen.lopnStyle   = fnPenStyle;
  27.         m_LogPen.lopnWidth.x = nWidth;
  28.         m_LogPen.lopnWidth.y = 0;
  29.         m_LogPen.lopnColor   = crColor;
  30.     }
  31.  
  32.     int GetObject(int cbBuffer, void * pBuffer)
  33.     {
  34.         if ( pBuffer==NULL )
  35.             return sizeof(LOGPEN);
  36.         else if ( cbBuffer>=sizeof(m_LogPen) )
  37.         {
  38.             memcpy(pBuffer, & m_LogPen, sizeof(m_LogPen));
  39.             return sizeof(LOGPEN);
  40.         }
  41.         else
  42.         {
  43.             SetLastError(ERROR_INVALID_PARAMETER);
  44.             return 0;
  45.         }
  46.     }
  47.  
  48.     bool DeleteObject(void)
  49.     {
  50.         if ( this )
  51.         {
  52.             delete this;
  53.             return true;
  54.         }
  55.         else
  56.             return false;
  57.     }
  58. };
  59.  
  60.  
  61. _Pen * _CreatePen(int fnPenStyle, int nWidth, COLORREF crColor)
  62. {
  63.     return new _RealPen(fnPenStyle, nWidth, crColor);
  64. }
  65.  
  66. void Test(void)
  67. {
  68.     _Pen * pPen = _CreatePen(PS_SOLID, 1, RGB(0, 0, 0xFF));
  69.     ////
  70.     pPen->DeleteObject();
  71. }