home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / sprmgr20 / sprite / demo16 / owndrw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  1.1 KB  |  57 lines

  1.  
  2. #include "stdafx.h"
  3.  
  4. #include "sprite.h"
  5. #include "sprmgr.h"
  6.  
  7. #include "owndrw.h"
  8.  
  9. COwnerDraw::COwnerDraw(int nID) 
  10.     : CSprite(nID, TRUE, TRUE, TRUE)
  11. {
  12. }
  13.  
  14. COwnerDraw::~COwnerDraw()
  15. {
  16. }
  17.  
  18. BOOL COwnerDraw::OnRenderSprite(CDC* pDC, CRect positionInfo, COLORREF& transparent, int nDrawingType)
  19. {
  20.     static long count = 0L;
  21.  
  22.     CBrush greenBrush;
  23.     greenBrush.CreateSolidBrush(RGB(0, 255, 0));
  24.  
  25.     pDC->FillRect(CRect(0, 0, positionInfo.Width(), positionInfo.Height()), &greenBrush);
  26.  
  27.     greenBrush.DeleteObject();
  28.  
  29.     CPen bluePen;
  30.     bluePen.CreatePen(PS_SOLID, 3, RGB(0, 0, 255));
  31.  
  32.     CPen* pOldPen = pDC->SelectObject(&bluePen);
  33.  
  34.     pDC->MoveTo(0,0);
  35.     pDC->LineTo(positionInfo.Width(), positionInfo.Height());
  36.  
  37.     pDC->MoveTo(positionInfo.Width(), 0);
  38.     pDC->LineTo(0, positionInfo.Height());
  39.  
  40.     pDC->SelectObject(pOldPen);
  41.     bluePen.DeleteObject();
  42.  
  43.     char text[50];
  44.     sprintf(text, "%ld", count);
  45.  
  46.     CSize textSize = pDC->GetTextExtent(text, strlen(text));
  47.     pDC->TextOut((positionInfo.Width() - textSize.cx) / 2, 
  48.                  0, 
  49.                  text, strlen(text));
  50.     
  51.     count++;
  52.  
  53.     transparent = RGB(0, 255, 0);
  54.  
  55.     return TRUE;
  56. }
  57.