#include #include "resource.h" #define GREEN 0x30D050 #define RED 0xE8 #define BLUE 0xF0A080 int v, w, x, y, z, xBid, yBid, xOld, yOld, one, passes, CardTop, index, Title, TitleAndMenu, HelpType; int tempSuits[4], SuitLengths[4][4]; // [WNES][SHCD] int WestSuitsCopy[4], NorthSuitsCopy[4], EastSuitsCopy[4], SouthSuitsCopy[4]; int SuitHeight, SuitWidth, SpadeWidth, HeartWidth, DiamondWidth, ClubWidth; int pts[] = {4,3,2,1,0,0,0,0,0,0,0,0,0}; DWORD ScreenWidth, ScreenHeight, xCenter, yCenter, CardWidth, CardHeight; DWORD WestLeft = 10, WestTop, DummyLeft, EastLeft, EastBiddingLeft, EastTop, HandLeft, HandTop; DWORD WestCard, NorthCard, EastCard, SouthCard, EWPlayedTop, EWCardTop, NorthCardTop, SouthCardTop; DWORD fileSize, dwBytesRead, dwBytesWritten; BYTE Balanced[4], Doubletons[4]; BYTE SuitSymbols[] = "\xAA\xA9\xA7\xA8"; // S H C D BYTE highcardpoints[4], lengthpoints[4]; BYTE b, Bidder, Declarer, Dealer = 3, DealerCopy; // Dealer 3 is South BYTE currentcard, cardsplayed, tricksplayed; char *PreviousGames; char *HelpBuf; char Savedtime[4124]; char SavedGames[] = "BridgeGames.txt"; char Comments[4096]; char BidSuit; char suitled, highcard, hightrump; char szAppName[] = "Bridge2"; char Suit[] = "AKQJT98765432"; char Suits[] = "SHCD"; char card[1], suit[1]; char TimesNewRoman[] = "Times New Roman"; char Symbol[] = "Symbol"; char West[] = "WEST", North[] = "NORTH", East[] = "EAST", South[] = "SOUTH"; char Bidding[] = " 's bid"; char TricksLost[] = "Tricks Lost: 0"; char Bid[20][20]; char LastBid[20] = "Bid: "; char Spade[] = " Spade"; char Spades[] = " Spades"; char Heart[] = " Heart"; char Hearts[] = " Hearts"; char Diamond[] = " Diamond"; char Diamonds[] = " Diamonds"; char Club[] = " Club"; char Clubs[] = " Clubs"; char NT[] = " NT"; char Pass[] = "Pass"; char Double[] = "Double"; char Redouble[] = "Redouble"; char HighCardPoints[10] = " Points"; BOOL bidding = TRUE, first = TRUE, showbid = FALSE, oldgame = FALSE, bidagain = FALSE; BOOL opener, responder, rebidder, responderrebidder; struct Kards { int Order; int RandomNumber; } cards[52]; struct Hands { BYTE number; // A = 0, K = 1, etc char card[2]; // card[0] = suit }; struct Hands west[13]; struct Hands north[13]; struct Hands east[13]; struct Hands south[13]; struct Hands temp[13]; struct Hands westcopy[13]; struct Hands northcopy[13]; struct Hands eastcopy[13]; struct Hands southcopy[13]; struct Hands *player; struct Hands Played[4]; // west north east south struct { int x; int y; BYTE player; BYTE card; BYTE suitnum; } Playing[4]; HANDLE hFile; SIZE Size; HWND hwnd, hwndBid, hwndOK; HINSTANCE hInst; HDC hdc, hdcMem = NULL; HBITMAP hBitmap; PAINTSTRUCT ps; RECT rect; HBRUSH hGreenBrush, hLeadingBrush, hOldBrush; HFONT hFont, hUpsideDownFont, hSuitFont, hSmallSuitFont, hUpsideDownSuitFont, hSmallUpsideDownSuitFont, hOldFont; LOGFONT lf, lfSuit; SYSTEMTIME st; FILETIME ft; ULARGE_INTEGER ul; WNDPROC pBidProc; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; WNDCLASS wndclass; hInst = hInstance; hGreenBrush = CreateSolidBrush(GREEN); hLeadingBrush = CreateSolidBrush(BLUE); wndclass.style = CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(hInstance, "ICON"); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = hGreenBrush; wndclass.lpszMenuName = "MENU"; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) return 0; hwnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL); ShowWindow(hwnd, SW_SHOWMAXIMIZED); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } /* void ShowHelp(char* Title) { if (fileSize = GetFileSize(hFile, NULL)) { HelpBuf = malloc(fileSize); ReadFile(hFile, HelpBuf, fileSize, &dwBytesRead, NULL); MessageBox(hwnd, HelpBuf, Title, MB_OK); free(HelpBuf); } CloseHandle(hFile); } */ //sub-class procedure LRESULT CALLBACK BidProc(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_KEYUP) { int x, y; char *p; p = NULL; switch (wParam) { case '1': one = 1; break; case '2': case '3': case '4': case '5': case '6': case '7': one = 2; break; case 'S': case 's': if (one == 1) p = Spade; else if (one != -1) p = Spades; else { SendMessage(hwndBid, EM_SETSEL, 0, -1); SendMessage(hwndBid, WM_CLEAR, 0, 0); } passes = 0; break; case 'H': case 'h': if (one == 1) p = Heart; else if (one == 2) p = Hearts; else if (one == -1) { SendMessage(hwndBid, EM_SETSEL, 0, -1); SendMessage(hwndBid, WM_CLEAR, 0, 0); /* for (x = 0; x <= Bidder; x++) { if (opener == FALSE) opener = TRUE; if ((opener == TRUE) && (responder == FALSE) && (x >= 2) && (Bid[x-2][0] >= '0') && (Bid[x-2][0] <= '7')) responder = TRUE; } if (responder) { if ((Bid[Bidder-2][0] == '1') && (Bid[Bidder-2][2] =='N')) { if (INVALID_HANDLE_VALUE != (hFile = CreateFile("ResponderTo1NTHelp.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) ShowHelp("Responding to 1 NoTrump"); else MessageBox(hwnd, "ResponderTo1NTHelp.txt not found", ERROR, MB_OK); } else if ((Bid[Bidder-2][0] == '2') && (Bid[Bidder-2][2] =='N')) MessageBox(hwnd, "Opener has 21 or 22 High Card Points\nUse Stayman if warrented", "Responder to 2 NoTrump", MB_OK); else if ((Bid[Bidder-2][0] == '3') && (Bid[Bidder-2][2] =='N')) MessageBox(hwnd, "Opener has 25 to 27 High Card Points", "Responder to 3 NoTrump", MB_OK); else if ((Bid[Bidder-2][0] == '2') && (Bid[Bidder-2][2] == 'C')) MessageBox(hwnd, "Opener has 22+ Total Points\n\nWith 0-7 Total Points\n BID 2 Diamonds", "Responder to 2 Clubs", MB_OK); else if (INVALID_HANDLE_VALUE != (hFile = CreateFile("ResponderHelp.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) ShowHelp("Responder Help"); else MessageBox(hwnd, "ResponderHelp.txt not found", ERROR, MB_OK); } else if (opener) { if (INVALID_HANDLE_VALUE != (hFile = CreateFile("OpenerHelp.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) ShowHelp("Opener"); else MessageBox(hwnd, "OpenerHelp.txt not found", ERROR, MB_OK); } SetFocus(hwndBid); */ } passes = 0; break; case 'D': case 'd': if (one == 1) { p = Diamond; passes = 0; } else if (one != -1) { p = Diamonds; passes = 0; } else if (one == -1) { for (x = Bidder; x >= 0; x--) { if ((Bid[x][0] >= '0') && (Bid[x][0] <= '7')) { p = Double; passes = 0; break; } } } break; case 'C': case 'c': if (one == 1) p = Club; else if (one != -1) p = Clubs; else { SendMessage(hwndBid, EM_SETSEL, 0, -1); SendMessage(hwndBid, WM_CLEAR, 0, 0); } passes = 0; break; case 'N': case 'n': if (one != -1) p = NT; else { SendMessage(hwndBid, EM_SETSEL, 0, -1); SendMessage(hwndBid, WM_CLEAR, 0, 0); } passes = 0; break; case 'P': case 'p': p = Pass; passes++; break; case 'R': case 'r': for (x = Bidder; x >= 0; x--) { if ((Bid[x][0] >= '0') && (Bid[x][0] <= '7')) { p = Redouble; passes = 0; break; } } break; default: one = -1; SendMessage(hwndBid, EM_SETSEL, 0, -1); SendMessage(hwndBid, WM_CLEAR, 0, 0); break; } if (p) { GetWindowText(hwndBid, Bid[Bidder], 20); if (one == -1) x = 0; else x = 1; for ( ; *p != 0; x++, p++) Bid[Bidder][x] = *p; Bid[Bidder][x] = 0; // if ((Bid[Bidder][0] != 'P') && (Bid[Bidder][0] != 'p')) { if ((Bid[Bidder][0] >= '1') && (Bid[Bidder][0] <= '7')) { for (x = 0, y = 5; Bid[Bidder][x] != 0; x++, y++) LastBid[y] = Bid[Bidder][x]; LastBid[y] = 0; } xOld = xBid; yOld = yBid; xBid += 80; if (xBid == 330) { xBid = 10; yBid += 30; } one = -1; showbid = TRUE; Bidder++; if (((LastBid[5] == 0) && (passes == 4)) || (passes < 5)) { DestroyWindow(hwndBid); first = TRUE; InvalidateRect(hwnd, &rect, FALSE); } } } return CallWindowProc(pBidProc, hwnd2, message, wParam, lParam); } int compare1(const void *x, const void *y) { if (((struct Kards*)x)->RandomNumber > ((struct Kards*)y)->RandomNumber) return 1; else if (((struct Kards*)x)->RandomNumber < ((struct Kards*)y)->RandomNumber) return -1; else return 0; } int compare2(const void *x, const void *y) { if (((struct Hands*)x)->number > ((struct Hands*)y)->number) return 1; else if (((struct Hands*)x)->number < ((struct Hands*)y)->number) return -1; else return 0; } void ConvertNumbersToNames(struct Hands *ptr, int CardsInSuits[4]) { if (ptr[x].number < 13) { ptr[x].card[0] = 'S'; CardsInSuits[0]++; } else if (ptr[x].number < 26) { ptr[x].card[0] = 'H'; CardsInSuits[1]++; } else if (ptr[x].number < 39) { ptr[x].card[0] = 'C'; CardsInSuits[2]++; } else {//if (ptr[x].number < 52) ptr[x].card[0] = 'D'; CardsInSuits[3]++; } ptr[x].card[1] = Suit[ptr[x].number % 13]; } void ShowCard(struct Hands *ptr, int x, int y, int v) { if ((ptr == player) && (currentcard == v)) { // currentcard is the ordinal number of the card in the hand (starting with 0) hOldBrush = SelectObject(hdcMem, hLeadingBrush); RoundRect(hdcMem, x, y, x+CardWidth, y+CardHeight, 12, 12); SelectObject(hdcMem, hOldBrush); } else RoundRect(hdcMem, x, y, x+CardWidth, y+CardHeight, 12, 12); suit[0] = SuitSymbols[w]; if ((SuitSymbols[w] == 0xA8) || (SuitSymbols[w] == 0xA9)) SetTextColor(hdcMem, RED); else SetTextColor(hdcMem, 0); // black hOldFont = SelectObject(hdcMem, hSmallSuitFont); TextOut(hdcMem, x+2, y + 18, suit, 1); SelectObject(hdcMem, hSmallUpsideDownSuitFont); TextOut(hdcMem, x+CardWidth-2, y+CardHeight-18, suit, 1); if (v < 13) // if v == 0xFF then card[0] = Playing[].card card[0] = ptr[v].card[1]; SelectObject(hdcMem, hFont); if (card[0] == 'T') TextOut(hdcMem, x-1, y+1, "10", 2); else if ((card[0] > '9') && (card[0] != 'J')) TextOut(hdcMem, x+3, y+1, card, 1); else TextOut(hdcMem, x+5, y+1, card, 1); SelectObject(hdcMem, hUpsideDownFont); if (card[0] == 'T') TextOut(hdcMem, x+CardWidth+1, y+CardHeight-1, "10", 2); else if ((card[0] > '9') && (card[0] != 'J')) TextOut(hdcMem, x+CardWidth-3, y+CardHeight-1, card, 1); else TextOut(hdcMem, x+CardWidth-5, y+CardHeight-1, card, 1); if ((card[0] == 'J') || (card[0] == 'Q') || (card[0] == 'K')) { MoveToEx(hdcMem, x+27, y+28, NULL); LineTo(hdcMem, x+27, y+CardHeight-28); LineTo(hdcMem, x+CardWidth-27, y+CardHeight-28); LineTo(hdcMem, x+CardWidth-27, y+28); LineTo(hdcMem, x+27, y+28); } SelectObject(hdcMem, hSuitFont); GetTextExtentPoint32(hdcMem, "\xAA", 1, &Size); SuitHeight = Size.cy; SpadeWidth = Size.cx; GetTextExtentPoint32(hdcMem, "\xA9", 1, &Size); HeartWidth = Size.cx; GetTextExtentPoint32(hdcMem, "\xA8", 1, &Size); DiamondWidth = Size.cx; GetTextExtentPoint32(hdcMem, "\xA7", 1, &Size); ClubWidth = Size.cx; if (suit[0] == '\xAA') SuitWidth = SpadeWidth; else if (suit[0] == '\xA9') SuitWidth = HeartWidth; else if (suit[0] == '\xA8') SuitWidth = DiamondWidth; else if (suit[0] == '\xA7') SuitWidth = ClubWidth; CardTop = y-3; switch (card[0]) { case '2': TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+CardHeight-SuitHeight, suit, 1); break; case '3': TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+CardHeight-SuitHeight, suit, 1); break; case '4': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; case '5': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; case '6': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; case '7': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)-(SuitHeight), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; case '8': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)-(SuitHeight), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)+(SuitHeight/8), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; case '9': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight/5), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight/5), suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)-(SuitHeight/2), suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight*4/5)-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight*4/5)-SuitHeight, suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; case 'T': TextOut(hdcMem, x+20, CardTop, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(SuitHeight/4), suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight/5), suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight/5), suit, 1); TextOut(hdcMem, x+20, CardTop+(CardHeight*4/5)-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+(CardHeight*4/5)-SuitHeight, suit, 1); TextOut(hdcMem, x+(CardWidth/2)-(SuitWidth/2), CardTop+(CardHeight/2)+(SuitHeight/4), suit, 1); TextOut(hdcMem, x+20, CardTop+CardHeight-SuitHeight, suit, 1); TextOut(hdcMem, x+CardWidth-20-SuitWidth, CardTop+CardHeight-SuitHeight, suit, 1); break; } SelectObject(hdcMem, hOldFont); } void NewDeal(void) { if (!oldgame) { Dealer++; if (Dealer == 4) Dealer = 0; } opener = responder = rebidder = responderrebidder = FALSE; Bidder = Dealer; currentcard = 0; tricksplayed = 0; TricksLost[13] = '0'; for (x = 0; x < 4; x++) Playing[x].player = 0xFF; for (x = 0; x < 20; x++) Bid[x][0] = 0; if (hwndBid) DestroyWindow(hwndBid); bidding = first = TRUE; passes = 0; LastBid[5] = 0; yBid = 30; if (Dealer == 0) xBid = 10; else if (Dealer == 1) xBid = 90; else if (Dealer == 2) xBid = 170; else// if (Dealer == 3) xBid = 250; for (x = 0; x < 4; x++) { for (y = 0; y < 4; y++) { SuitLengths[x][y] = 0; } } //shuffle if (oldgame == FALSE) GetLocalTime(&st); else oldgame = FALSE; SystemTimeToFileTime(&st, &ft); ul.LowPart = ft.dwLowDateTime; ul.HighPart = ft.dwHighDateTime; ul.QuadPart /= 10000;//because low 4 digits are 0's srand(ul.LowPart); srand((UINT)rand()); for (x = 0; x < 52; x++) { cards[x].Order = x; cards[x].RandomNumber = rand(); } qsort(cards, 52, sizeof(struct Kards), compare1); //deal for (x = 0, y = 0; x < 52; y++) { west[y].number = cards[x++].Order; north[y].number = cards[x++].Order; east[y].number = cards[x++].Order; south[y].number = cards[x++].Order; } //sort hands qsort(west, 13, sizeof(struct Hands), compare2); qsort(north, 13, sizeof(struct Hands), compare2); qsort(east, 13, sizeof(struct Hands), compare2); qsort(south, 13, sizeof(struct Hands), compare2); //convert numbers to names for (x = 0; x < 13; x++) { ConvertNumbersToNames(west, SuitLengths[0]); ConvertNumbersToNames(north, SuitLengths[1]); ConvertNumbersToNames(east, SuitLengths[2]); ConvertNumbersToNames(south, SuitLengths[3]); } for (x = 0; x < 13; x++) westcopy[x] = west[x]; for (x = 0; x < 13; x++) northcopy[x] = north[x]; for (x = 0; x < 13; x++) eastcopy[x] = east[x]; for (x = 0; x < 13; x++) southcopy[x] = south[x]; for (x = 0; x < 4; x++) { *(WORD*)&Played[x].card = 0x2020; WestSuitsCopy[x] = SuitLengths[0][x]; NorthSuitsCopy[x] = SuitLengths[1][x]; EastSuitsCopy[x] = SuitLengths[2][x]; SouthSuitsCopy[x] = SuitLengths[3][x]; Balanced[x] = 1; Doubletons[x] = 0; } for (x = 0; x < 4; x++) { if (SuitLengths[0][x] == 2) Doubletons[0]++; if (SuitLengths[1][x] == 2) Doubletons[1]++; if (SuitLengths[2][x] == 2) Doubletons[2]++; if (SuitLengths[3][x] == 2) Doubletons[3]++; if ((SuitLengths[0][x] < 2) || (Doubletons[0] == 2)) Balanced[0] = 0; if ((SuitLengths[1][x] < 2) || (Doubletons[1] == 2)) Balanced[1] = 0; if ((SuitLengths[2][x] < 2) || (Doubletons[2] == 2)) Balanced[2] = 0; if ((SuitLengths[3][x] < 2) || (Doubletons[3] == 2)) Balanced[3] = 0; } DealerCopy = Dealer; } void ShowPoints(int player) { HighCardPoints[0] = (highcardpoints[player] / 10) + '0'; if (HighCardPoints[0] == '0') HighCardPoints[0] = ' '; HighCardPoints[1] = (highcardpoints[player] % 10) + '0'; TextOut(hdcMem, x, y, HighCardPoints, 9); } int CALLBACK PreviousGamesProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndList; switch (message) { case WM_INITDIALOG: hwndList = GetDlgItem(hwndDlg, IDC_LIST1); for (x = 0, index = 0; x < (int)fileSize; index++) { y = x; for (x += 24; PreviousGames[x] != '\n'; x++) ; x++; PreviousGames[x-2] = 0; SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)&PreviousGames[y]); } SendMessage(hwndList, LB_SETCURSEL, index-1, 0); SetFocus(hwndList); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: index = SendMessage(hwndList, LB_GETCURSEL, 0, 0); EndDialog (hwndDlg, TRUE); return TRUE; case IDCANCEL: EndDialog (hwndDlg, FALSE); return FALSE; } } return FALSE; } int CALLBACK HelpProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { int dlgWidth; static HWND hwndEdit; RECT dlgRect, rectEdit; switch (message) { case WM_INITDIALOG: if (HelpType == 1) SetWindowText(hwndDlg, "Opening"); else if (HelpType == 2) SetWindowText(hwndDlg, "Responding"); else if (HelpType == 3) SetWindowText(hwndDlg, "Responding to 1 NT"); else if (HelpType == 4) SetWindowText(hwndDlg, "Opener's Rebid"); else if (HelpType == 5) SetWindowText(hwndDlg, "Responder's Rebid"); GetWindowRect(hwndDlg, &dlgRect); dlgWidth = dlgRect.right-dlgRect.left; MoveWindow(hwndDlg, (rect.right/2)-(dlgWidth/2), TitleAndMenu, dlgWidth, rect.bottom, TRUE); hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT1); MoveWindow(hwndEdit, 0, 0, dlgWidth, rect.bottom-Title, TRUE); GetClientRect(hwndEdit, & rectEdit); rectEdit.left += 10; SendMessage(hwndEdit, EM_SETRECT, 0, (LPARAM)(LPRECT)&rectEdit); SetWindowText(hwndEdit, HelpBuf); SetFocus(hwndEdit); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog (hwndDlg, TRUE); break; case IDCANCEL: EndDialog (hwndDlg, FALSE); break; } } return 0; } void Help(void) { if (fileSize = GetFileSize(hFile, NULL)) { HelpBuf = malloc(fileSize+1); ReadFile(hFile, HelpBuf, fileSize, &dwBytesRead, NULL); HelpBuf[fileSize] = 0; DialogBox(hInst, "BIDDINGHELP", hwnd, HelpProc); free(HelpBuf); } CloseHandle(hFile); } int CALLBACK CommentsProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndEdit; switch (message) { case WM_INITDIALOG: hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT1); SetFocus(hwndEdit); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: GetWindowText(hwndEdit, Comments, 4095); EndDialog (hwndDlg, TRUE); break; case IDCANCEL: EndDialog (hwndDlg, FALSE); break; } } return 0; } /////////////////////////////////////////////////////////////////////////////// LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: hwndBid = NULL; lf.lfWeight = 700; lf.lfItalic = 0; lf.lfUnderline = 0; lf.lfStrikeOut = 0; lf.lfCharSet = 0; lf.lfOutPrecision = 3;//1; lf.lfClipPrecision = 2; lf.lfQuality = 1; lf.lfPitchAndFamily = 34;//0x22; for (x = 0; TimesNewRoman[x] != 0; x++) lf.lfFaceName[x] = TimesNewRoman[x]; lf.lfFaceName[x] = 0; lfSuit.lfWeight = 400; lfSuit.lfItalic = 0; lfSuit.lfUnderline = 0; lfSuit.lfStrikeOut = 0; lfSuit.lfCharSet = 0; lfSuit.lfOutPrecision = 1; lfSuit.lfClipPrecision = 2; lfSuit.lfQuality = 1; lfSuit.lfPitchAndFamily = 0x22; for (x = 0; Symbol[x] != 0; x++) lfSuit.lfFaceName[x] = Symbol[x]; lfSuit.lfFaceName[x] = 0; NewDeal(); Title = GetSystemMetrics(SM_CYCAPTION); TitleAndMenu = Title + GetSystemMetrics(SM_CYMENU); return 0; case WM_SIZE: GetClientRect(hwnd, &rect); if (hdcMem) { DeleteDC (hdcMem); DeleteObject (hBitmap); } hdc = GetDC(hwnd); hdcMem = CreateCompatibleDC(hdc); hBitmap = CreateCompatibleBitmap(hdc, rect.right, rect.bottom); ReleaseDC(hwnd, hdc); SelectObject(hdcMem, hBitmap); FillRect(hdcMem, &rect, hGreenBrush); ScreenWidth = LOWORD(lParam);// redundant... ScreenHeight = HIWORD(lParam);// redundant... xCenter = ScreenWidth / 2; yCenter = ScreenHeight / 2; // card proportion is 5:7 CardWidth = 5 * ScreenWidth / 51;// 125 CardHeight = 7 * ScreenWidth / 51;//175 HandTop = ScreenHeight - CardHeight - 10; WestTop = EastTop = HandTop - 10 - CardHeight - (CardHeight*3/3); DummyLeft = xCenter - (CardWidth*2) - 25; // EastLeft = xCenter + CardWidth + (40 * 4) + 20; EastLeft = xCenter + (CardWidth * 2) + 50; EastBiddingLeft = ScreenWidth - 10 - CardWidth - (12*25); HandLeft = xCenter - ((CardWidth + (12 * 25))/2); EWCardTop = yCenter-(CardHeight/2); EWPlayedTop = HandTop - CardHeight - (CardHeight/6) - 10; WestCard = xCenter-(CardWidth*3/4); NorthCardTop = HandTop - CardHeight - (CardHeight/3) - 10; NorthCard = xCenter-(CardWidth/2); EastCard = xCenter-(CardWidth/4); SouthCardTop = HandTop - CardHeight - 10; SouthCard = xCenter-(CardWidth/2); if (rect.right >= 1600) { lf.lfHeight = -29; lfSuit.lfHeight = -59; // big suit symbol } else if (rect.right >= 1200) { lf.lfHeight = -27; lfSuit.lfHeight = -45; } else { // if (rect.right == 1024) { lf.lfHeight = -23; lfSuit.lfHeight = -35; // big suit symbol } lf.lfEscapement = lf.lfOrientation = 1800; hUpsideDownFont = CreateFontIndirect(&lf); lf.lfEscapement = lf.lfOrientation = 0; hFont = CreateFontIndirect(&lf); lfSuit.lfEscapement = lfSuit.lfOrientation = 1800; hUpsideDownSuitFont = CreateFontIndirect(&lfSuit); lfSuit.lfEscapement = lfSuit.lfOrientation = 0; hSuitFont = CreateFontIndirect(&lfSuit); if (rect.right >= 1600) { lf.lfHeight = -31; lfSuit.lfHeight = -31; // small suit symbol } else if (rect.right >= 1200) lfSuit.lfHeight = -27; // small suit symol else // if (rect.right == 1024) lfSuit.lfHeight = -21; hSmallSuitFont = CreateFontIndirect(&lfSuit); lfSuit.lfEscapement = lfSuit.lfOrientation = 1800; hSmallUpsideDownSuitFont = CreateFontIndirect(&lfSuit); // first = TRUE; return 0; case WM_COMMAND: if ((hwndOK) && (HWND)lParam == hwndOK) { SendMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); return 0; } switch (LOWORD(wParam)) { case ID_FILES_SAVEGAME: x = 0; Savedtime[x++] = (st.wYear / 1000) + '0'; Savedtime[x++] = ((st.wYear % 1000) / 100) + '0'; Savedtime[x++] = ((st.wYear % 100) / 10) + '0'; Savedtime[x++] = (st.wYear % 10) + '0'; Savedtime[x++] = ' '; Savedtime[x++] = (st.wMonth / 10) + '0'; Savedtime[x++] = (st.wMonth % 10) + '0'; Savedtime[x++] = ' '; Savedtime[x++] = (st.wDay / 10) + '0'; Savedtime[x++] = (st.wDay % 10) + '0'; Savedtime[x++] = ' '; Savedtime[x++] = (st.wHour / 10) + '0'; Savedtime[x++] = (st.wHour % 10) + '0'; Savedtime[x++] = (st.wMinute / 10) + '0'; Savedtime[x++] = (st.wMinute % 10) + '0'; Savedtime[x++] = ':'; Savedtime[x++] = (st.wSecond / 10) + '0'; Savedtime[x++] = (st.wSecond % 10) + '0'; Savedtime[x++] = ':'; Savedtime[x++] = (st.wMilliseconds / 100) + '0'; Savedtime[x++] = ((st.wMilliseconds % 100) / 10) + '0'; Savedtime[x++] = (st.wMilliseconds % 10) + '0'; Savedtime[x++] = ' '; Savedtime[x++] = Dealer + '0'; if (DialogBox(hInst, "COMMENTS", NULL, CommentsProc)) { Savedtime[x++] = ' '; for (y = 0; Comments[y]; x++, y++) Savedtime[x] = Comments[y]; } Savedtime[x++] = '\r'; Savedtime[x++] = '\n'; hFile = CreateFile(SavedGames, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL); SetFilePointer(hFile, 0, NULL, FILE_END); WriteFile(hFile, Savedtime, x, &dwBytesWritten, NULL); CloseHandle(hFile); Savedtime[x-1] = 0; MessageBox(hwnd, Savedtime, SavedGames, MB_OK); Savedtime[x-1] = '\r'; break; case ID_FILES_PREVIOUSGAMES: if (INVALID_HANDLE_VALUE != (hFile = CreateFile(SavedGames, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL))) { fileSize = GetFileSize(hFile, NULL); if (fileSize) { PreviousGames = (char*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); ReadFile(hFile, PreviousGames, fileSize, &dwBytesRead, NULL) ; if (DialogBox(hInst, "PREVIOUSGAMES", NULL, PreviousGamesProc)) { for (x = 0, y = 0; y < index; y++) { for ( ; PreviousGames[x] != '\n'; x++) ; x++; } st.wYear = ((PreviousGames[x]-'0')*1000) + ((PreviousGames[x+1]-'0')*100) + ((PreviousGames[x+2]-'0')*10) + (PreviousGames[x+3]-'0'); x += 5; st.wMonth = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0'); x += 3; st.wDay = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0'); x += 3; st.wHour = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0'); x += 2; st.wMinute = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0'); x += 3; st.wSecond = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0'); x += 3; st.wMilliseconds = ((PreviousGames[x]-'0')*100) + ((PreviousGames[x+1]-'0')*10) + (PreviousGames[x+2]-'0'); x += 4; if ((PreviousGames[x] >= '0') && (PreviousGames[x] <= '3')) Dealer = PreviousGames[x] - '0'; else Dealer = 0; oldgame = TRUE; } VirtualFree(PreviousGames, 0, MEM_RELEASE); } CloseHandle(hFile); if (oldgame) { DestroyWindow(hwndBid); SendMessage(hwnd, WM_COMMAND, ID_NEWDEAL, 0); } } else { MessageBox(hwnd, "not found in this folder", SavedGames, MB_OK); } break; case ID_FILES_EXIT: DestroyWindow(hwnd); break; case ID_NEWDEAL: DestroyWindow(hwndOK); NewDeal(); InvalidateRect(hwnd, &rect, FALSE); break; case ID_AGAIN_BID: DestroyWindow(hwndOK); DestroyWindow(hwndBid); opener = responder = rebidder = responderrebidder = FALSE; Dealer = DealerCopy; Bidder = Dealer; passes = 0; for (x = 0; x < 20; x++) Bid[x][0] = 0; LastBid[5] = 0; yBid = 30; if (Dealer == 0) xBid = 10; else if (Dealer == 1) xBid = 90; else if (Dealer == 2) xBid = 170; else// if (Dealer == 3) xBid = 250; bidagain = TRUE; // fall thru... case ID_AGAIN_PLAY: if ((bidagain == TRUE) || (bidding == FALSE)) { bidding = first = TRUE; for (x = 0; x < 13; x++) west[x] = westcopy[x]; for (x = 0; x < 13; x++) north[x] = northcopy[x]; for (x = 0; x < 13; x++) east[x] = eastcopy[x]; for (x = 0; x < 13; x++) south[x] = southcopy[x]; for (x = 0; x < 4; x++) { *(WORD*)&Played[x].card = 0x2020; SuitLengths[0][x] = WestSuitsCopy[x]; SuitLengths[1][x] = NorthSuitsCopy[x]; SuitLengths[2][x] = EastSuitsCopy[x]; SuitLengths[3][x] = SouthSuitsCopy[x]; } cardsplayed = 0; currentcard = 0; tricksplayed = 0; TricksLost[13] = '0'; for (x = 0; x < 4; x++) Playing[x].player = 0xFF; if (bidagain) { bidagain = FALSE; InvalidateRect(hwnd, &rect, FALSE); } else SendMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0); } break; case HELP_USING: MessageBox(hwnd, "Use Enter and the Arrow keys","", MB_OK); if (bidding) SetFocus(hwndBid); break; case HELP_OPENING: if (INVALID_HANDLE_VALUE != (hFile = CreateFile("Opening.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) { HelpType = 1; Help(); } else MessageBox(hwnd, "'Opening.txt'\nisn't in this folder", ERROR, MB_OK); SetFocus(hwndBid); break; case ID_HELP_RESPONDING: if (INVALID_HANDLE_VALUE != (hFile = CreateFile("Responding.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) { HelpType = 2; Help(); } else MessageBox(hwnd, "'Responding.txt'\nisn't in this folder", ERROR, MB_OK); SetFocus(hwndBid); break; case ID_HELP_RESPONDINGTO1NT: if (INVALID_HANDLE_VALUE != (hFile = CreateFile("Responding to 1 NT.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) { HelpType = 3; Help(); } else MessageBox(hwnd, "'Responding to 1 NT.txt'\nisn't in this folder", ERROR, MB_OK); SetFocus(hwndBid); break; case ID_HELP_OPENERSREBID: if (INVALID_HANDLE_VALUE != (hFile = CreateFile("Opener Rebid.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) { HelpType = 4; Help(); } else MessageBox(hwnd, "'Opener Rebid.txt'\nisn't in this folder", ERROR, MB_OK); SetFocus(hwndBid); break; case ID_HELP_RESPONDERSREBID: if (INVALID_HANDLE_VALUE != (hFile = CreateFile("Responder Rebid.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL))) { HelpType = 5; Help(); } else MessageBox(hwnd, "'Responder Rebid.txt'\nisn't in this folder", ERROR, MB_OK); SetFocus(hwndBid); break; case HELP_ABOUT: MessageBox(hwnd, "by Doug Cox\njdmcox.com", "Bridge2", MB_OK); break; } return 0; // case WM_MOUSEMOVE: // if (!bidding) { // PLAYING // x=x; // } // return 0; case WM_KEYDOWN: if ((bidding) && (wParam == VK_RETURN)) { // bidding ended int x, y; DestroyWindow(hwndOK); if (passes == 4) { NewDeal(); } else { bidding = FALSE; for (x = Bidder-1; x >= 0; x--) { if ((Bid[x][0] >= '1') && (Bid[x][0] <= '7')) break; } BidSuit = Bid[x][2]; if (x & 1) y = 1; else y = 0; for ( ; y <= x; y += 2) { if ((Bid[y][0] != 'P') && (Bid[y][2] == BidSuit)) { Declarer = y % 4; for (x = Declarer; x != 3; ) { // make Declarer South for (y = 0; y < 13; y++) { temp[y] = north[y]; north[y] = west[y]; west[y] = south[y]; south[y] = east[y]; east[y] = temp[y]; } for (y = 0; y < 4; y++) { tempSuits[y] = SuitLengths[1][y]; SuitLengths[1][y] = SuitLengths[0][y]; SuitLengths[0][y] = SuitLengths[3][y]; SuitLengths[3][y] = SuitLengths[2][y]; SuitLengths[2][y] = tempSuits[y]; } x++; if (x == 4) x = 0; } break; } } } cardsplayed = 0; player = west; InvalidateRect(hwnd, &rect, FALSE); } else if (!bidding) { // PLAYING int x; if (wParam == VK_RIGHT) { if ((player == west) || (player == east)) { if (player[currentcard+1].card[0] == player[currentcard].card[0]) {// same suit currentcard++; } } else if (player == north) { for (x = currentcard; x < 12; x++) { if ((player[x+1].card[0] != player[x].card[0]) && (player[x+1].card[0] != 0x7F)) { currentcard = x+1; break; // next suit } } } else if (player == south) { if ((currentcard < 12) && (player[currentcard+1].card[0] != 0x7F)) { currentcard++; } } } else if (wParam == VK_DOWN) { if ((player == west) || (player == east)) { for (x = currentcard; x < 12; x++) { if ((player[x+1].card[0] != player[x].card[0]) && (player[x+1].card[0] != 0x7F)) { currentcard = x+1; break; // next suit } } } else if (player == north) { if (player[currentcard+1].card[0] == player[currentcard].card[0]) {// same suit currentcard++; } } } else if (wParam == VK_LEFT) { if ((player == west) || (player == east)) { if ((currentcard) && (player[currentcard-1].card[0] == player[currentcard].card[0])) {// same suit currentcard--; } } else if (player == north) { for (x = currentcard; (x > 0) && (player[x-1].card[0] == player[x].card[0]); x--) ; if (x) { for (x--; player[x-1].card[0] == player[x].card[0]; x--) ; } currentcard = x; } else if (player == south) { if (currentcard) { currentcard--; } } } else if (wParam == VK_UP) { if ((player == west) || (player == east)) { for (x = currentcard; (x > 0) && (player[x-1].card[0] == player[x].card[0]); x--) ; if (x) { for (x--; player[x-1].card[0] == player[x].card[0]; x--) ; } currentcard = x; } else if (player == north) { if ((currentcard) && (player[currentcard-1].card[0] == player[currentcard].card[0])) {// same suit currentcard--; } } } else if (wParam == VK_RETURN) { if (tricksplayed != 52) { if (cardsplayed == 0) { suitled = player[currentcard].card[0]; } else if (player[currentcard].card[0] != suitled) { for (x = 0; (x < 13) && (player[x].number != 0xFF); x++) { if (player[x].card[0] == suitled) { return 0; } } } if (player == west) { Played[0] = west[currentcard]; for (x = 0; west[currentcard].card[0] != Suits[x]; x++) ; if (SuitLengths[0][x]) SuitLengths[0][x]--; Playing[cardsplayed].card = west[currentcard].card[1]; Playing[cardsplayed].x = WestCard; Playing[cardsplayed].y = EWPlayedTop; Playing[cardsplayed].player = 0; Playing[cardsplayed].suitnum = x; for (x = currentcard; x < 12; x++) west[x] = west[x+1]; // remove card played west[x].card[0] = 0x7F; player = north; } else if (player == north) { Played[1] = north[currentcard]; for (x = 0; north[currentcard].card[0] != Suits[x]; x++) ; if (SuitLengths[1][x]) SuitLengths[1][x]--; Playing[cardsplayed].card = north[currentcard].card[1]; Playing[cardsplayed].x = NorthCard; Playing[cardsplayed].y = NorthCardTop; Playing[cardsplayed].player = 1; Playing[cardsplayed].suitnum = x; for (x = currentcard; x < 12; x++) north[x] = north[x+1]; // remove card played north[x].card[0] = 0x7F; player = east; } else if (player == east) { Played[2] = east[currentcard]; for (x = 0; east[currentcard].card[0] != Suits[x]; x++) ; if (SuitLengths[2][x]) SuitLengths[2][x]--; Playing[cardsplayed].card = east[currentcard].card[1]; Playing[cardsplayed].x = EastCard; Playing[cardsplayed].y = EWPlayedTop; Playing[cardsplayed].player = 2; Playing[cardsplayed].suitnum = x; for (x = currentcard; x < 12; x++) east[x] = east[x+1]; // remove card played east[x].card[0] = 0x7F; player = south; } else if (player == south) { Played[3] = south[currentcard]; for (x = 0; south[currentcard].card[0] != Suits[x]; x++) ; if (SuitLengths[3][x]) SuitLengths[3][x]--; Playing[cardsplayed].card = south[currentcard].card[1]; Playing[cardsplayed].x = SouthCard; Playing[cardsplayed].y = SouthCardTop; Playing[cardsplayed].player = 3; Playing[cardsplayed].suitnum = x; for (x = currentcard; x < 12; x++) south[x] = south[x+1]; // remove card played south[x].card[0] = 0x7F; player = west; } cardsplayed++; if (cardsplayed == 4) { // round played cardsplayed = 0; highcard = 14; hightrump = 14; for (x = 0; x < 4; x++) Playing[x].player = 0xFF; if ((Played[0].number%13 < highcard) && (Played[0].card[0] == suitled) && (hightrump == 14)) { player = west; highcard = Played[0].number%13; } else if ((Played[0].card[0] != suitled) && (BidSuit != 'N') && (Played[0].card[0] == BidSuit)) { player = west; hightrump = Played[0].number%13; } if ((Played[1].number%13 < highcard) && (Played[1].card[0] == suitled) && (hightrump == 14)) { player = north; highcard = Played[1].number%13; } else if ((Played[1].card[0] != suitled) && (BidSuit != 'N') && (Played[1].card[0] == BidSuit) && (Played[1].number%13 < hightrump)) { player = north; hightrump = Played[1].number%13; } if ((Played[2].number%13 < highcard) && (Played[2].card[0] == suitled) && (hightrump == 14)) { player = east; highcard = Played[2].number%13; } else if ((Played[2].card[0] != suitled) && (BidSuit != 'N') && (Played[2].card[0] == BidSuit) && (Played[2].number%13 < hightrump)) { player = east; hightrump = Played[2].number%13; } if ((Played[3].number%13 < highcard) && (Played[3].card[0] == suitled) && (hightrump == 14)) { player = south; highcard = Played[3].number%13; } else if ((Played[3].card[0] != suitled) && (BidSuit != 'N') && (Played[3].card[0] == BidSuit) && (Played[3].number%13 < hightrump)) { player = south; hightrump = Played[3].number%13; } if ((player == west) || (player == east)) TricksLost[13]++; } tricksplayed++; currentcard = 0; // for next hand } } InvalidateRect(hwnd, &rect, FALSE); } return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); FillRect(hdcMem, &rect, hGreenBrush); SetBkMode(hdcMem, TRANSPARENT); if (bidding) { player = NULL; highcardpoints[0] = highcardpoints[1] = highcardpoints[2] = highcardpoints[3] = 0; for (x = 0; x < 13; x++) {//get high card points highcardpoints[0] += pts[(west[x].number) % 13]; highcardpoints[1] += pts[(north[x].number) % 13]; highcardpoints[2] += pts[(east[x].number) % 13]; highcardpoints[3] += pts[(south[x].number) % 13]; } SetTextColor(hdcMem, 0xFFFFFF); TextOut(hdcMem, 10, 10, West, 4); TextOut(hdcMem, 90, 10, North, 5); TextOut(hdcMem, 170, 10, East, 4); TextOut(hdcMem, 250, 10, South, 5); hOldFont = SelectObject(hdcMem, hFont); SelectObject(hdcMem, hOldFont); if (((LastBid[5] == 0) && (passes == 3)) || (passes < 3)) { if (Bidder%4 == 0) { Bidding[0] = ' '; for (x = 1, y = 0; x < 5; x++, y++) Bidding[x] = West[y]; TextOut(hdcMem, WestLeft, EWCardTop-20, Bidding, 11); // WEST } else if (Bidder%4 == 1) { for (x = 0; x < 5; x++) Bidding[x] = North[x]; TextOut(hdcMem, HandLeft, 10+CardHeight+10, Bidding, 11); // NORTH } else if (Bidder%4 == 2) { Bidding[0] = ' '; for (x = 1, y = 0; x < 5; x++, y++) Bidding[x] = East[y]; TextOut(hdcMem, EastBiddingLeft, EWCardTop-20, Bidding, 11); // EAST } else if (Bidder%4 == 3) { for (x = 0; x < 5; x++) Bidding[x] = South[x]; TextOut(hdcMem, HandLeft, HandTop-20, Bidding, 11); // SOUTH } } for (v = 0, x = WestLeft, y = EWCardTop, w = 0; w < 4; w++) { for (z = 0; z < SuitLengths[0][w]; v++, x += 25, z++) ShowCard(west, x, y, v); } ShowPoints(0); for (v = 0, x = HandLeft, y = 10, w = 0; w < 4; w++) { for (z = 0; z < SuitLengths[1][w]; v++, x += 25, z++) ShowCard(north, x, y, v); } ShowPoints(1); for (v = 0, x = EastBiddingLeft, y = EWCardTop, w = 0; w < 4; w++) { for (z = 0; z < SuitLengths[2][w]; v++, x += 25, z++) ShowCard(east, x, y, v); } ShowPoints(2); for (v = 0, x = HandLeft, y = HandTop, w = 0; w < 4; w++) { for (z = 0; z < SuitLengths[3][w]; v++, x += 25, z++) ShowCard(south, x, y, v); } ShowPoints(3); one = -1; if (first) { first = FALSE; hwndBid = CreateWindow("EDIT", NULL, WS_CHILD | WS_VISIBLE, xBid, yBid, 50, 20, hwnd, (HMENU)1, hInst, NULL); pBidProc = (WNDPROC)SetWindowLong(hwndBid, GWL_WNDPROC, (LONG)BidProc); SetFocus(hwndBid); } SetTextColor(hdcMem, 0xFFFFFF); for (x = 10, y = 30, z = 0; z <= Bidder; z++) { if (Bid[z]) TextOut(hdcMem, x, y, Bid[z], strlen(Bid[z])); x += 80; if (x == 330) { x = 10; y += 30; } } for (v = 0, x = HandLeft, y = 10, w = 0; w < 4; w++) {// because it gets over-written at 1024x786 for (z = 0; z < SuitLengths[1][w]; v++, x += 25, z++) ShowCard(north, x, y, v); } ShowPoints(1); if (showbid) { showbid = FALSE; if (((LastBid[5]) && (passes == 3)) || (passes == 4)) { DestroyWindow(hwndBid); hwndOK = CreateWindow("BUTTON", "OK", WS_CHILD | WS_VISIBLE, xBid, yBid, 80, 20, hwnd, (HMENU)2, hInst, NULL); SetFocus(hwnd); } } } // end of if (bidding) else { // if playing SetTextColor(hdcMem, 0xFFFFFF); TextOut(hdcMem, 10, 10, LastBid, strlen(LastBid)); TextOut(hdcMem, 10, 30, TricksLost, 14); SetTextColor(hdcMem, 0); for (z = 0; z < 4; z++) { // show played cards if (Playing[z].player != 0xFF) { x = Playing[z].x; y = Playing[z].y; v = 0xFF; // flag w = Playing[z].suitnum; card[0] = Playing[z].card; ShowCard(player, x, y, v); } } y = WestTop; for (v = 0, w = 0; w < 4; w++, y += (CardHeight/3)) { for (x = WestLeft, z = 0; z < SuitLengths[0][w]; x += 25, z++, v++) { // WEST ShowCard(west, x, y, v); } } y = EastTop; for (v = 0, w = 0; w < 4; w++, y += (CardHeight/3)) { for (x = EastLeft, z = 0; z < SuitLengths[2][w]; x += 25, z++, v++) { // EAST ShowCard(east, x, y, v); } } y = 10; for (v = 0, x = DummyLeft, w = 0; w < 4; w++, x += (CardWidth + 20)) for (y = 10, z = 0; z < SuitLengths[1][w]; v++, y += 28, z++) { // NORTH ShowCard(north, x, y, v); } y = HandTop; for (v = 0, x = HandLeft, w = 0; w < 4; w++) { for (y = HandTop, z = 0; z < SuitLengths[3][w]; v++, x += 25, z++) { // SOUTH ShowCard(south, x, y, v); } } } BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }