home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Direkt: Spezial 1
/
CDD_SPIELE_.ISO
/
wingames
/
pyramid
/
cardwin.cpp
next >
Wrap
C/C++ Source or Header
|
1993-08-18
|
6KB
|
247 lines
//-------------------------------------------------------------------
// PROGRAM: CARDWIN.CPP
//
// DESCRIPTION: Sub-window class that will represent each
// card in the deck.
//
// Written by Carlos Yu
//
// NOTE: The program design is kinda hacked because
// this is my first attempt at creating a
// fully functional Windows program using
// OWL and C++.
//
// Any suggestions on making the program better,
// specially the DealCards module which is
// painfully slow, would be greatly appreciated.
//
// Compuserve ID 72672,1567
//-------------------------------------------------------------------
#include <owl.h>
#include "cardwin.h"
UINT NOTIFY_PARENT = (WM_USER + 20);
//-------------------------------------------------------------------
// CLASS: TCardWin
//
// MEMBER: Constructor
//
// ARGUMENTS: AParent - the parent window
// ATitle - the window title
// Idx - card array index
// X - horizontal position
// Y - vertical position
//
// RETURNS: NONE
//-------------------------------------------------------------------
TCardWin::TCardWin(PTWindowsObject AParent, LPSTR ATitle, int Idx,
int X, int Y, HINSTANCE Instance) : TWindow(AParent, ATitle)
{
xPos = X;
yPos = Y;
deckIndex = Idx;
appInstance = Instance;
(PTWindowsObject) myParent = AParent;
//----------------------------
// Where the card goes
//----------------------------
if ( deckIndex <= 22 )
{
faceUp = FALSE;
where = INPYRAMID;
dependentCard = WhichDependent(deckIndex);
}
else
if ( deckIndex <= 29 )
{
faceUp = TRUE;
where = INPYRAMID;
}
else
{
faceUp = FALSE;
where = INDECK;
}
//----------------------------
// Default window attributes
//----------------------------
Attr.X = DECK_X;
Attr.Y = DECK_Y + (DECK_Y % 2);
Attr.W = CARDWIDTH;
Attr.H = CARDHEIGHT;
Attr.Style = WS_CHILD |
WS_VISIBLE |
WS_CLIPSIBLINGS;
}
//-------------------------------------------------------------------
// CLASS: TCardWin
//
// MEMBER: WMDestroy
//
// DESCRIPTION: Clean up before exit
//
// ARGUMENTS: Windows message
//
// RETURNS: NONE
//-------------------------------------------------------------------
void TCardWin::WMDestroy(RTMessage Msg)
{
TWindow::WMDestroy(Msg);
}
//-------------------------------------------------------------------
// CLASS: TCardWin
//
// MEMBER: GetWindowClass
//
// DESCRIPTION: Alter the default background
//
// ARGUMENTS: AWndClass - structure that contains the
// default registration attributes
// of this window
//
// RETURNS: NONE
//-------------------------------------------------------------------
void TCardWin::GetWindowClass(WNDCLASS& AWndClass)
{
TWindow::GetWindowClass(AWndClass);
AWndClass.hbrBackground = NULL;
}
//-------------------------------------------------------------------
// CLASS: TCardWin
//
// MEMBER: Paint
//
// DESCRIPTION: Display the background bitmap
//
// ARGUMENTS: hDC - screen handle
//
// RETURNS: NONE
//-------------------------------------------------------------------
void TCardWin::Paint(HDC hDC, PAINTSTRUCT _FAR &)
{
HBITMAP hBitBkgnd;
if ( faceUp )
hBitBkgnd = LoadBitmap(appInstance, MAKEINTRESOURCE(bitNum));
else
hBitBkgnd = LoadBitmap(appInstance, MAKEINTRESOURCE(FACEDN));
hDC = GetDC(HWindow);
HDC hMemDC = CreateCompatibleDC(hDC);
HDC TempDC = SelectObject(hMemDC, hBitBkgnd);
if ( cardTagged )
BitBlt(hDC, 0, 0, CARDWIDTH, CARDHEIGHT, hMemDC, 0, 0,
NOTSRCCOPY);
else
BitBlt(hDC, 0, 0, CARDWIDTH, CARDHEIGHT, hMemDC, 0, 0,
SRCCOPY);
SelectObject(hMemDC, TempDC);
DeleteDC(hMemDC);
ReleaseDC(HWindow, hDC);
DeleteObject(hBitBkgnd);
}
//-------------------------------------------------------------------
// CLASS: TCardWin
//
// MEMBER: WhichDependent
//
// DESCRIPTION: Get the index of the first of two cards
// that prevents this card from showing itself
// face-up in the pyramid area
//
// ARGUMENTS: This card's index value
//
// RETURNS: The index of the first dependent card
//-------------------------------------------------------------------
int TCardWin::WhichDependent(int deckIdx)
{
int row;
switch ( deckIdx )
{
case 1:
row = 1;
break;
case 2:
case 3:
row = 2;
break;
case 4:
case 5:
case 6:
row = 3;
break;
case 7:
case 8:
case 9:
case 10:
row = 4;
break;
case 11:
case 12:
case 13:
case 14:
case 15:
row = 5;
break;
default:
row = 6;
break;
}
return ( deckIdx + row );
}
//-------------------------------------------------------------------
// CLASS: TCardWin
//
// MEMBER: WMLButtonDown
//
// DESCRIPTION: What to do when user clicks on this card
//
// ARGUMENTS: RTMessage - not used
//
// RETURNS: NONE
//-------------------------------------------------------------------
void TCardWin::WMLButtonDown(RTMessage)
{
SendMessage(myParent->HWindow, NOTIFY_PARENT,
(WORD) deckIndex, NULL);
}