Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
10 KiB

  1. /****************************************************************************
  2. FREECELL.H
  3. June 91, JimH initial code
  4. Oct 91, JimH port to Win32
  5. Main header file for Windows Free Cell. Constants are in freecons.h
  6. ****************************************************************************/
  7. #include <windows.h>
  8. #include <port1632.h>
  9. #define WINHEIGHT 480
  10. #define WINWIDTH 640
  11. #define FACEUP 0 // card mode
  12. #define FACEDOWN 1
  13. #define HILITE 2
  14. #define GHOST 3
  15. #define REMOVE 4
  16. #define INVISIBLEGHOST 5
  17. #define DECKX 6
  18. #define DECKO 7
  19. #define EMPTY 0xFFFFFFFF
  20. #define IDGHOST 52 // eg, empty free cell
  21. #define MAXPOS 21
  22. #define MAXCOL 9 // includes top row as column 0
  23. #define MAXMOVELIST 150 // size of movelist array
  24. #define TOPROW 0 // column 0 is really the top row
  25. #define BLACK 0 // COLOUR(card)
  26. #define RED 1
  27. #define ACE 0 // VALUE(card)
  28. #define DEUCE 1
  29. #define CLUB 0 // SUIT(card)
  30. #define DIAMOND 1
  31. #define HEART 2
  32. #define SPADE 3
  33. #define FROM 0 // wMouseMode
  34. #define TO 1
  35. #define ICONWIDTH 32 // in pixels
  36. #define ICONHEIGHT 32
  37. #define BIG 128 // str buf sizes
  38. #define SMALL 32
  39. #define MAXGAMENUMBER 1000000
  40. #define CANCELGAME (MAXGAMENUMBER + 1)
  41. #define NONE 0 // king bitmap identifiers
  42. #define SAME 1
  43. #define RIGHT 2
  44. #define LEFT 3
  45. #define SMILE 4
  46. #define BMWIDTH 32 // bitmap width
  47. #define BMHEIGHT 32 // bitmap height
  48. #define LOST 0 // used for streaks
  49. #define WON 1
  50. #define FLASH_TIMER 2 // timer id for main window flash
  51. #define FLASH_INTERVAL 400 // flash timer interval
  52. #define FLIP_TIMER 3 // timer id for flipping column
  53. #define FLIP_INTERVAL 300
  54. #define CHEAT_LOSE 1 // used with bCheating
  55. #define CHEAT_WIN 2
  56. /* Macros */
  57. #define SUIT(card) ((card) % 4)
  58. #define VALUE(card) ((card) / 4)
  59. #define COLOUR(card) (SUIT(card) == 1 || SUIT(card) == 2)
  60. #define REGOPEN RegCreateKey(HKEY_CURRENT_USER, pszRegPath, &hkey);
  61. #define REGCLOSE RegCloseKey(hkey);
  62. #define DeleteValue(v) RegDeleteValue(hkey, v)
  63. /* Types */
  64. typedef INT CARD;
  65. typedef struct { // movelist made up of these
  66. UINT fcol;
  67. UINT fpos;
  68. UINT tcol;
  69. UINT tpos;
  70. } MOVE;
  71. /* Callback function prototypes */
  72. // INT PASCAL MMain(HANDLE, HANDLE, LPSTR, INT);
  73. LRESULT APIENTRY MainWndProc(HWND, UINT, WPARAM, LPARAM);
  74. INT_PTR APIENTRY About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  75. INT_PTR APIENTRY GameNumDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  76. INT_PTR APIENTRY MoveColDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  77. INT_PTR APIENTRY StatsDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  78. INT_PTR APIENTRY YouLoseDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  79. INT_PTR APIENTRY YouWinDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  80. INT_PTR APIENTRY OptionsDlg(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  81. /* Functions imported from cards.dll */
  82. BOOL APIENTRY cdtInit(UINT FAR *pdxCard, UINT FAR *pdyCard);
  83. BOOL APIENTRY cdtDraw(HDC hdc, INT x, INT y, INT cd, INT mode, DWORD rgbBgnd);
  84. BOOL APIENTRY cdtDrawExt(HDC hdc, INT x, INT y, INT dx, INT dy, INT cd,
  85. INT mode, DWORD rgbBgnd);
  86. BOOL APIENTRY cdtTerm(VOID);
  87. /* Other function prototypes */
  88. VOID CalcOffsets(HWND hWnd);
  89. UINT CalcPercentage(UINT cWins, UINT cLosses);
  90. VOID Card2Point(UINT col, UINT pos, UINT *x, UINT *y);
  91. VOID Cleanup(VOID);
  92. VOID CreateMenuFont(VOID);
  93. VOID DisplayCardCount(HWND hWnd);
  94. VOID DrawCard(HDC hDC, UINT col, UINT pos, CARD c, INT mode);
  95. VOID DrawCardMem(HDC hMemDC, CARD c, INT mode);
  96. VOID DrawKing(HDC hDC, UINT state, BOOL bDraw);
  97. UINT FindLastPos(UINT col);
  98. BOOL FitsUnder(CARD fcard, CARD tcard);
  99. VOID Flash(HWND hWnd);
  100. VOID Flip(HWND hWnd);
  101. UINT GenerateRandomGameNum(VOID);
  102. CHAR *GetHelpFileName(VOID);
  103. INT GetInt(CONST TCHAR *pszValue, INT nDefault);
  104. VOID Glide(HWND hWnd, UINT fcol, UINT fpos, UINT tcol, UINT tpos);
  105. VOID GlideStep(HDC hDC, UINT x1, UINT y1, UINT x2, UINT y2);
  106. BOOL InitApplication(HANDLE hInstance);
  107. BOOL InitInstance(HANDLE hInstance, INT nCmdShow);
  108. VOID IsGameLost(HWND hWnd);
  109. BOOL IsValidMove(HWND hWnd, UINT tcol, UINT tpos);
  110. VOID KeyboardInput(HWND hWnd, UINT keycode);
  111. UINT MaxTransfer(VOID);
  112. UINT MaxTransfer2(UINT freecells, UINT freecols);
  113. VOID MoveCards(HWND hWnd);
  114. VOID MoveCol(UINT fcol, UINT tcol);
  115. VOID MultiMove(UINT fcol, UINT tcol);
  116. UINT NumberToTransfer(UINT fcol, UINT tcol);
  117. VOID PaintMainWindow(HWND hWnd);
  118. VOID Payoff(HDC hDC);
  119. BOOL Point2Card(UINT x, UINT y, UINT *col, UINT *pos);
  120. BOOL ProcessDoubleClick(HWND hWnd);
  121. VOID ProcessMoveRequest(HWND hWnd, UINT x, UINT y);
  122. VOID ProcessTimer(HWND hWnd);
  123. VOID QueueTransfer(UINT fcol, UINT fpos, UINT tcol, UINT tpos);
  124. VOID ReadOptions(VOID);
  125. VOID RestoreColumn(HWND hWnd);
  126. VOID RevealCard(HWND hWnd, UINT x, UINT y);
  127. VOID SetCursorShape(HWND hWnd, UINT x, UINT y);
  128. VOID SetFromLoc(HWND hWnd, UINT x, UINT y);
  129. LONG SetInt(CONST TCHAR *pszValue, INT n);
  130. VOID ShuffleDeck(HWND hWnd, UINT_PTR seed);
  131. VOID StartMoving(HWND hWnd);
  132. VOID Transfer(HWND hWnd, UINT fcol, UINT fpos, UINT tcol, UINT tpos);
  133. VOID Undo(HWND hWnd);
  134. VOID UpdateLossCount(VOID);
  135. BOOL Useless(CARD c);
  136. VOID WMCreate(HWND hWnd);
  137. VOID WriteOptions(VOID);
  138. /* Global variables */
  139. TCHAR bigbuf[BIG]; // general purpose LoadString() buffer
  140. CHAR bighelpbuf[BIG]; // general purpose char buffer.
  141. BOOL bCheating; // hit magic key to win?
  142. BOOL bDblClick; // honor double click?
  143. BOOL bFastMode; // hidden option, don't do glides?
  144. BOOL bFlipping; // currently flipping cards in a column?
  145. BOOL bGameInProgress; // true if game is in progress
  146. BOOL bMessages; // are "helpful" MessageBoxen shown?
  147. BOOL bMonochrome; // 2 colour display?
  148. BOOL bMoveCol; // did user request column move (or 1 card)?
  149. BOOL bSelecting; // is user selecting game numbers?
  150. BOOL bWonState; // TRUE if game won and new game not started
  151. UINT dxCrd, dyCrd; // extents of card bitmaps in pixels
  152. CARD card[MAXCOL][MAXPOS]; // current layout of cards
  153. INT cFlashes; // count of main window flashes remaining
  154. UINT cGames; // number of games played in current session
  155. UINT cLosses; // number of losses in current session
  156. UINT cWins; // number of wins in current session
  157. UINT cMoves; // number of moves in this game
  158. UINT dyTops; // vert space between cards in columns
  159. CARD shadow[MAXCOL][MAXPOS]; // shadows card array for multi-moves & cleanup
  160. INT gamenumber; // current game number (rand seed)
  161. HBITMAP hBM_Ghost; // bitmap for ghost (empty) free/home cells
  162. HBITMAP hBM_Bgnd1; // screen under source location
  163. HBITMAP hBM_Bgnd2; // screen under destination location
  164. HBITMAP hBM_Fgnd; // bitmap that moves across screen
  165. HICON hIconMain; // the main freecell icon.
  166. HKEY hkey; // registry key
  167. HPEN hBrightPen; // 3D highlight colour
  168. HANDLE hInst; // current instance
  169. HWND hMainWnd; // hWnd for main window
  170. HFONT hMenuFont; // for Cards Left display
  171. CARD home[4]; // card on top of home pile for this suit
  172. CARD homesuit[4]; // suit for each home pile
  173. HBRUSH hBgndBrush; // green background brush
  174. UINT_PTR idTimer; // flash timer id
  175. UINT moveindex; // index to end of movelist
  176. MOVE movelist[MAXMOVELIST]; // compacted list of pending moves for timer
  177. INT oldgamenumber; // previous game (repeats don't count in score)
  178. TCHAR *pszIni; // .ini filename
  179. TCHAR smallbuf[SMALL]; // generic small buffer for LoadString()
  180. TCHAR titlebuf[BIG]; // a buffer used to store the window title.
  181. UINT wCardCount; // cards not yet in home cells (0 == win)
  182. UINT wFromCol; // col user has selected to transfer from
  183. UINT wFromPos; // pos "
  184. UINT wMouseMode; // selecting place to transfer FROM or TO
  185. UINT xOldLoc; // previous location of cards left text
  186. INT cUndo; // number of cards to undo
  187. /* registry value names */
  188. extern CONST TCHAR pszRegPath[];
  189. extern CONST TCHAR pszWon[];
  190. extern CONST TCHAR pszLost[];
  191. extern CONST TCHAR pszWins[];
  192. extern CONST TCHAR pszLosses[];
  193. extern CONST TCHAR pszStreak[];
  194. extern CONST TCHAR pszSType[];
  195. extern CONST TCHAR pszMessages[];
  196. extern CONST TCHAR pszQuick[];
  197. extern CONST TCHAR pszDblClick[];
  198. extern CONST TCHAR pszAlreadyPlayed[];
  199. /* TRACE mechanism */
  200. #if 0
  201. TCHAR szDebugBuffer[256];
  202. #define DEBUGMSG(parm1,parm2)\
  203. { wsprintf(szDebugBuffer,parm1,parm2);\
  204. OutputDebugString(szDebugBuffer); }
  205. #define assert(p) { if (!(p)) {wsprintf(szDebugBuffer, TEXT("assert: %s %d\r\n"),\
  206. __FILE__, __LINE__); OutputDebugString(szDebugBuffer);}}
  207. #else
  208. #define DEBUGMSG(parm1,parm2)
  209. #endif
  210. #define SPY(parm1) // not used in NT version