home *** CD-ROM | disk | FTP | other *** search
/ CD Direkt: Spezial 1 / CDD_SPIELE_.ISO / wingames / pyramid / cardwin.cpp next >
C/C++ Source or Header  |  1993-08-18  |  6KB  |  247 lines

  1. //-------------------------------------------------------------------
  2. //  PROGRAM:          CARDWIN.CPP
  3. //
  4. //  DESCRIPTION:      Sub-window class that will represent each
  5. //                    card in the deck.
  6. //
  7. //                    Written by Carlos Yu
  8. //
  9. //  NOTE:             The program design is kinda hacked because
  10. //                    this is my first attempt at creating a
  11. //                    fully functional Windows program using
  12. //                    OWL and C++.
  13. //
  14. //                    Any suggestions on making the program better,
  15. //                    specially the DealCards module which is
  16. //                    painfully slow, would be greatly appreciated.
  17. //
  18. //                    Compuserve ID 72672,1567
  19. //-------------------------------------------------------------------
  20.  
  21. #include <owl.h>
  22.  
  23. #include "cardwin.h"
  24.  
  25. UINT NOTIFY_PARENT = (WM_USER + 20);
  26.  
  27. //-------------------------------------------------------------------
  28. //  CLASS:              TCardWin
  29. //
  30. //  MEMBER:             Constructor
  31. //
  32. //  ARGUMENTS:          AParent - the parent window
  33. //                      ATitle  - the window title
  34. //                      Idx     - card array index
  35. //                      X       - horizontal position
  36. //                      Y       - vertical position
  37. //
  38. //  RETURNS:            NONE
  39. //-------------------------------------------------------------------
  40.  
  41. TCardWin::TCardWin(PTWindowsObject AParent, LPSTR ATitle, int Idx,
  42.     int X, int Y, HINSTANCE Instance) : TWindow(AParent, ATitle)
  43. {
  44.     xPos        = X;
  45.     yPos        = Y;
  46.     deckIndex   = Idx;
  47.     appInstance = Instance;
  48.     (PTWindowsObject) myParent = AParent;
  49.  
  50.     //----------------------------
  51.     //  Where the card goes
  52.     //----------------------------
  53.  
  54.     if ( deckIndex <= 22 )
  55.     {
  56.         faceUp = FALSE;
  57.         where  = INPYRAMID;
  58.  
  59.         dependentCard = WhichDependent(deckIndex);
  60.     }
  61.     else
  62.         if ( deckIndex <= 29 )
  63.         {
  64.             faceUp = TRUE;
  65.             where  = INPYRAMID;
  66.         }
  67.     else
  68.         {
  69.             faceUp = FALSE;
  70.             where  = INDECK;
  71.         }
  72.  
  73.     //----------------------------
  74.     //  Default window attributes
  75.     //----------------------------
  76.  
  77.     Attr.X      = DECK_X;
  78.     Attr.Y      = DECK_Y + (DECK_Y % 2);
  79.     Attr.W      = CARDWIDTH;
  80.     Attr.H      = CARDHEIGHT;
  81.     Attr.Style  = WS_CHILD |
  82.                   WS_VISIBLE |
  83.                   WS_CLIPSIBLINGS;
  84. }
  85.  
  86.  
  87. //-------------------------------------------------------------------
  88. //  CLASS:              TCardWin
  89. //
  90. //  MEMBER:             WMDestroy
  91. //
  92. //  DESCRIPTION:        Clean up before exit
  93. //
  94. //  ARGUMENTS:          Windows message
  95. //
  96. //  RETURNS:            NONE
  97. //-------------------------------------------------------------------
  98.  
  99. void TCardWin::WMDestroy(RTMessage Msg)
  100. {
  101.     TWindow::WMDestroy(Msg);
  102. }
  103.     
  104.  
  105.  
  106. //-------------------------------------------------------------------
  107. //  CLASS:              TCardWin
  108. //
  109. //  MEMBER:             GetWindowClass
  110. //
  111. //  DESCRIPTION:        Alter the default background
  112. //
  113. //  ARGUMENTS:          AWndClass - structure that contains the
  114. //                                  default registration attributes
  115. //                                  of this window
  116. //
  117. //  RETURNS:            NONE
  118. //-------------------------------------------------------------------
  119.  
  120. void TCardWin::GetWindowClass(WNDCLASS& AWndClass)
  121. {
  122.     TWindow::GetWindowClass(AWndClass);
  123.  
  124.     AWndClass.hbrBackground = NULL;
  125. }
  126.  
  127.  
  128. //-------------------------------------------------------------------
  129. //  CLASS:              TCardWin
  130. //
  131. //  MEMBER:             Paint
  132. //
  133. //  DESCRIPTION:        Display the background bitmap
  134. //
  135. //  ARGUMENTS:          hDC - screen handle
  136. //
  137. //  RETURNS:            NONE
  138. //-------------------------------------------------------------------
  139.  
  140. void TCardWin::Paint(HDC hDC, PAINTSTRUCT _FAR &)
  141. {
  142.     HBITMAP hBitBkgnd;
  143.  
  144.  
  145.     if ( faceUp )
  146.         hBitBkgnd = LoadBitmap(appInstance, MAKEINTRESOURCE(bitNum));
  147.     else
  148.         hBitBkgnd = LoadBitmap(appInstance, MAKEINTRESOURCE(FACEDN));
  149.  
  150.  
  151.     hDC = GetDC(HWindow);
  152.     HDC hMemDC = CreateCompatibleDC(hDC);
  153.     HDC TempDC = SelectObject(hMemDC, hBitBkgnd);
  154.  
  155.  
  156.     if ( cardTagged )
  157.         BitBlt(hDC, 0, 0, CARDWIDTH, CARDHEIGHT, hMemDC, 0, 0,
  158.             NOTSRCCOPY);
  159.     else
  160.         BitBlt(hDC, 0, 0, CARDWIDTH, CARDHEIGHT, hMemDC, 0, 0,
  161.             SRCCOPY);
  162.  
  163.  
  164.     SelectObject(hMemDC, TempDC);
  165.     DeleteDC(hMemDC);
  166.     ReleaseDC(HWindow, hDC);
  167.     DeleteObject(hBitBkgnd);
  168. }
  169.  
  170.  
  171. //-------------------------------------------------------------------
  172. //  CLASS:              TCardWin
  173. //
  174. //  MEMBER:             WhichDependent
  175. //
  176. //  DESCRIPTION:        Get the index of the first of two cards
  177. //                      that prevents this card from showing itself
  178. //                      face-up in the pyramid area
  179. //
  180. //  ARGUMENTS:          This card's index value
  181. //
  182. //  RETURNS:            The index of the first dependent card
  183. //-------------------------------------------------------------------
  184.  
  185. int TCardWin::WhichDependent(int deckIdx)
  186. {
  187.     int row;
  188.  
  189.     switch ( deckIdx )
  190.     {
  191.         case  1:
  192.             row = 1;
  193.             break;
  194.  
  195.         case  2:
  196.         case  3:
  197.             row = 2;
  198.             break;
  199.  
  200.         case  4:
  201.         case  5:
  202.         case  6:
  203.             row = 3;
  204.             break;
  205.  
  206.         case  7:
  207.         case  8:
  208.         case  9:
  209.         case 10:
  210.             row = 4;
  211.             break;
  212.  
  213.         case 11:
  214.         case 12:
  215.         case 13:
  216.         case 14:
  217.         case 15:
  218.             row = 5;
  219.             break;
  220.  
  221.         default:
  222.             row = 6;
  223.             break;
  224.     }
  225.  
  226.     return ( deckIdx + row );
  227. }                
  228.  
  229.  
  230. //-------------------------------------------------------------------
  231. //  CLASS:              TCardWin
  232. //
  233. //  MEMBER:             WMLButtonDown
  234. //
  235. //  DESCRIPTION:        What to do when user clicks on this card
  236. //
  237. //  ARGUMENTS:          RTMessage - not used
  238. //
  239. //  RETURNS:            NONE
  240. //-------------------------------------------------------------------
  241.  
  242. void TCardWin::WMLButtonDown(RTMessage)
  243. {
  244.     SendMessage(myParent->HWindow, NOTIFY_PARENT,
  245.         (WORD) deckIndex, NULL);
  246. }
  247.