home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / com / connect / mdrive / driver.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-03  |  1.5 KB  |  78 lines

  1. // Driver.cpp : Implementation of CDriveApp and DLL registration.
  2.  
  3. #include "premdriv.h"
  4. #include "Driver.h"
  5.  
  6. extern HDC hDrawDC;
  7. extern int nHeight;
  8. extern int nThreads;
  9.  
  10. LONG g_cLockCnt = 0L;
  11. LONG g_cObjCnt = 0L;
  12. /////////////////////////////////////////////////////////////////////////////
  13. //
  14.  
  15. STDMETHODIMP CRandomEvent::put_Fire(long l)
  16. {
  17.     m_cs.Lock();
  18.     foo pos;
  19.     if (!m_mapPos.Lookup(l, pos))
  20.     {
  21.         m_mapPos[l] = foo();
  22.     }
  23.     COLORREF cr = RGB(255,255,255);
  24.     switch (l)
  25.     {
  26.     case 0:
  27.         cr = RGB(255,0,0);
  28.         break;
  29.     case 1:
  30.         cr = RGB(0,255,0);
  31.         break;
  32.     case 2:
  33.         cr = RGB(0,0,255);
  34.         break;
  35.     case 3:
  36.         cr = RGB(255,255,0);
  37.         break;
  38.     case 4:
  39.         cr = RGB(255,0,255);
  40.         break;
  41.     case 5:
  42.         cr = RGB(0,255,255);
  43.         break;
  44.     case 6:
  45.         cr = RGB(64,64,64);
  46.         break;
  47.     case 7:
  48.         cr = RGB(128,128,128);
  49.         break;
  50.     case 8:
  51.         cr = RGB(192,192,192);
  52.         break;
  53.     case 9:
  54.         cr = RGB(0,0,0);
  55.         break;
  56.     }
  57.     int nH = nHeight/nThreads;
  58.     if (pos.nDir == 1)
  59.         SetPixel(hDrawDC, m_nID, nH*l+pos.nPos, cr);
  60.     else
  61.         SetPixel(hDrawDC, m_nID, nH*l+pos.nPos, RGB(0,0,0));
  62.     pos.nPos += pos.nDir;
  63.     if (pos.nPos >= nH)
  64.     {
  65.         pos.nDir = -1;
  66.         pos.nPos = nH-1;
  67.     }
  68.     if (pos.nPos <= -1)
  69.     {
  70.         pos.nDir = 1;
  71.         pos.nPos = 0;
  72.     }
  73.     m_mapPos[l] = pos;
  74.     m_cs.Unlock();
  75.     GdiFlush();
  76.     return S_OK;
  77. }
  78.