Source code of Windows XP (NT5)
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.

235 lines
7.4 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. main.h
  7. CMainWindow object
  8. This class encompasses most of what is interesting in the main window of
  9. Hearts.
  10. Aug 92, JimH
  11. ****************************************************************************/
  12. #ifndef STRICT
  13. #define STRICT
  14. #endif
  15. #include "regentry.h"
  16. #include "player.h"
  17. #include "computer.h"
  18. #include "dlg.h"
  19. #include "dde.h"
  20. #ifndef MAIN_INC
  21. #define MAIN_INC
  22. // non-translateable strings
  23. extern const TCHAR szRegPath[];
  24. extern const TCHAR regvalSound[];
  25. extern const TCHAR regvalName[];
  26. extern const TCHAR regvalRole[];
  27. extern const TCHAR regvalSpeed[];
  28. extern const TCHAR regvalServer[];
  29. extern const TCHAR *regvalPName[3];
  30. extern const TCHAR szHelpFileName[];
  31. extern const TCHAR szShareName[];
  32. const int WINWIDTH = 540;
  33. const int WINHEIGHT = 480;
  34. const int LEFT = 0; // passdir
  35. const int RIGHT = 1;
  36. const int ACROSS = 2;
  37. const int NOPASS = 3;
  38. const int OFF = 0; // used in PlaySound
  39. const int MAXNAMELENGTH = 14;
  40. const int MAXCOMPUTERNAME = 15;
  41. enum roletype { GAMEMEISTER, PLAYER };
  42. // The following structures are used to pass around DDE data
  43. typedef struct {
  44. int id;
  45. TCHAR name[4][MAXNAMELENGTH+3]; // might have square brackets too!
  46. } GAMESTATUS;
  47. typedef struct { // I'm passing these three cards
  48. int id;
  49. int passdir;
  50. int cardid[3];
  51. } PASS3;
  52. typedef struct { // the complete set of passed cards
  53. int passdir;
  54. int cardid[MAXPLAYER][3];
  55. } PASS12;
  56. typedef struct { // sent out after each move
  57. int playerid;
  58. int cardid;
  59. int playerled;
  60. int turn;
  61. } MOVE;
  62. #if defined (MFC1)
  63. UINT FAR PASCAL EXPORT TimerDispatch(HWND, UINT, int, DWORD);
  64. #else
  65. void FAR PASCAL EXPORT TimerDispatch(HWND, UINT, UINT, DWORD);
  66. #endif
  67. class CMainWindow : public CFrameWnd
  68. {
  69. friend player::player(int n, int pos);
  70. friend void player::GlideToCentre(SLOT s, BOOL bFaceup);
  71. friend HDDEDATA EXPENTRY EXPORT DdeServerCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  72. friend HDDEDATA EXPENTRY EXPORT DdeClientCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  73. #if defined(MFC1)
  74. friend UINT FAR PASCAL EXPORT TimerDispatch(HWND, UINT, int, DWORD);
  75. #else
  76. friend void FAR PASCAL EXPORT TimerDispatch(HWND, UINT, UINT_PTR, DWORD);
  77. #endif
  78. public:
  79. CMainWindow(LPTSTR lpCmdLine);
  80. void FatalError(int errorno = -1);
  81. int GetGameNumber() { return m_gamenumber; }
  82. COLORREF GetBkColor() { return m_bkgndcolor; }
  83. CString GetPlayerName(int num) { return p[num]->GetName(); }
  84. modetype GetPlayerMode(int num) { return p[num]->GetMode(); }
  85. int GetMyId() { return m_myid; }
  86. int Id2Pos(int id) { return ((id - m_myid + 4) % 4); }
  87. BOOL IsFirstBloodEnforced() { return bEnforceFirstBlood; }
  88. void PlayerQuit(int id);
  89. int Pos2Id(int pos) { return ((pos + m_myid) % 4); }
  90. void SetGameNumber(int num) { m_gamenumber = num; }
  91. afx_msg void OnAbout();
  92. afx_msg void OnBossKey() { ShowWindow(SW_MINIMIZE); }
  93. afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  94. afx_msg void OnCheat();
  95. afx_msg void OnClose();
  96. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  97. afx_msg BOOL OnEraseBkgnd(CDC *);
  98. afx_msg void OnExit() { bConstructed = FALSE; OnClose(); }
  99. afx_msg void OnHelp()
  100. { ::HtmlHelp(::GetDesktopWindow(), szHelpFileName, HH_DISPLAY_TOPIC, 0); }
  101. /*
  102. afx_msg void OnHelpOnHelp()
  103. { ::WinHelp(m_hWnd, NULL, HELP_HELPONHELP, 0); }
  104. */
  105. afx_msg void OnHideButton() { m_Button.EnableWindow(FALSE); }
  106. /*
  107. afx_msg void OnSearch()
  108. { ::WinHelp(m_hWnd, szHelpFileName, HELP_PARTIALKEY,
  109. (DWORD_PTR)(LPSTR)""); }
  110. */
  111. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  112. afx_msg void OnNewGame();
  113. afx_msg void OnOptions();
  114. afx_msg void OnPaint();
  115. afx_msg void OnPass();
  116. afx_msg void OnQuote();
  117. afx_msg void OnRef();
  118. afx_msg void OnShowButton() { m_Button.EnableWindow();
  119. m_Button.SetFocus(); }
  120. afx_msg void OnScore();
  121. afx_msg void OnSound();
  122. afx_msg void OnWelcome();
  123. afx_msg LRESULT OnPrintClient(WPARAM wParam, LPARAM lParam);
  124. private:
  125. int AddNewPlayer(HCONV hConv, HDDEDATA hData);
  126. void CheckNddeShare();
  127. void ClientConnect(CString& server, CString& myname);
  128. int CountClients();
  129. BOOL CreateStrHandles();
  130. HDDEDATA DdeSrvCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  131. HDDEDATA DdeCliCallBack(WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
  132. void DestroyStrHandles();
  133. void DoSort();
  134. void DispatchCards();
  135. void EndHand();
  136. void FirstMove();
  137. void GameOver();
  138. HDDEDATA GetGameStatus(HCONV hConv);
  139. void GetPass12(PASS12& pass12);
  140. void HandleMove(MOVE& move);
  141. void HandlePass(PASS3& pass3);
  142. BOOL HandlePassing();
  143. BOOL IsCurrentPlayer(HCONV hConv, int *id);
  144. void ResetHandInfo(int playernumber);
  145. void Shuffle();
  146. BOOL SoundInit();
  147. BOOL HeartsPlaySound(int id);
  148. void ReceivePassFromClient(HDDEDATA hData);
  149. void ReceiveMove(MOVE& move);
  150. void UpdatePassStatus(PASS12& pass12);
  151. void UpdateStatusNames(GAMESTATUS& gs);
  152. CButton m_Button;
  153. int m_StatusHeight;
  154. CScoreDlg *m_pScoreDlg;
  155. BOOL bAutostarted;
  156. BOOL bCheating;
  157. BOOL bConstructed;
  158. BOOL bEnforceFirstBlood;
  159. BOOL bHasSound;
  160. BOOL bNetDdeActive;
  161. BOOL bSoundOn;
  162. BOOL bTimerOn;
  163. int m_gamenumber;
  164. LPTSTR m_lpCmdLine;
  165. player *p[MAXPLAYER];
  166. int m_myid;
  167. int passdir;
  168. int m_FatalErrno;
  169. COLORREF m_bkgndcolor;
  170. handinfotype handinfo;
  171. roletype role;
  172. int tricksleft;
  173. int trickwinner;
  174. static CBrush m_BgndBrush;
  175. static CRect m_TableRect;
  176. DECLARE_MESSAGE_MAP()
  177. };
  178. // global variables
  179. extern CMainWindow *pMainWnd;
  180. extern HSZ hszJoin;
  181. extern HSZ hszPass;
  182. extern HSZ hszMove;
  183. extern HSZ hszStatus;
  184. extern HSZ hszGameNumber;
  185. extern HSZ hszPassUpdate;
  186. extern DDE *dde;
  187. extern MOVE move;
  188. extern MOVE moveq[8];
  189. extern int cQdMoves;
  190. extern PASS3 passq[4];
  191. extern int cQdPasses;
  192. extern int nStatusHeight;
  193. #endif