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.

167 lines
4.2 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. welcome.cpp
  7. Aug 92, JimH
  8. May 93, JimH chico port
  9. more CMainWindow member functions
  10. CTheApp::InitInstance() posts a IDM_WELCOME message as soon as it has
  11. constructed and shown the main window. This file includes that message's
  12. handler (OnWelcome) and some support routines.
  13. ****************************************************************************/
  14. #include "hearts.h"
  15. #include "main.h"
  16. #include "resource.h"
  17. #include "debug.h"
  18. /****************************************************************************
  19. CMainWindow::OnWelcome()
  20. Pop up the Welcome dialog.
  21. ****************************************************************************/
  22. void CMainWindow::OnWelcome()
  23. {
  24. // bugbug -- what should "hearts" string really be?
  25. BOOL bCmdLine = (*m_lpCmdLine != '\0');
  26. bAutostarted = (lstrcmpi(m_lpCmdLine, TEXT("hearts")) == 0);
  27. if (bAutostarted)
  28. HeartsPlaySound(SND_QUEEN); // tell new dealer someone wants to play
  29. CWelcomeDlg welcome(this);
  30. if (!bAutostarted && !bCmdLine)
  31. {
  32. if (IDCANCEL == welcome.DoModal()) // display Welcome dialog
  33. {
  34. PostMessage(WM_CLOSE);
  35. return;
  36. }
  37. }
  38. if (bAutostarted || welcome.IsGameMeister()) // if Gamemeister
  39. {
  40. CClientDC dc(this);
  41. #ifdef USE_MIRRORING
  42. SetLayout(dc.m_hDC, 0);
  43. SetLayout(dc.m_hAttribDC, 0);
  44. #endif
  45. role = GAMEMEISTER;
  46. m_myid = 0;
  47. p[0]->SetStatus(IDS_GMWAIT);
  48. CString name = welcome.GetMyName();
  49. if (name.IsEmpty())
  50. name.LoadString(IDS_DEALER);
  51. p[0]->SetName(name, dc);
  52. p[0]->DisplayName(dc);
  53. PostMessage(WM_COMMAND, IDM_NEWGAME);
  54. return;
  55. }
  56. }
  57. /****************************************************************************
  58. CMainWindow::FatalError()
  59. A static BOOL prevents this function from being called reentrantly. One is
  60. enough, and more than one leaves things in bad states. The parameter is
  61. the IDS_X constant that identifies the string to display.
  62. There is also a check that we don't try to shut down while the score dialog
  63. is displayed. This avoids some nasty debug traps when the score dialog
  64. doesn't shut down properly. The same problems can happen if, say, a dealer
  65. quits when a client is looking at the quote. Oh well.
  66. ****************************************************************************/
  67. void CMainWindow::FatalError(int errorno)
  68. {
  69. if (p[0]->GetMode() == SCORING)
  70. {
  71. m_FatalErrno = errorno;
  72. return;
  73. }
  74. static BOOL bClosing = FALSE;
  75. if (bClosing)
  76. return;
  77. bClosing = TRUE;
  78. if (errno != -1) // if not default
  79. {
  80. CString s1, s2;
  81. s1.LoadString(errno);
  82. s2.LoadString(IDS_APPNAME);
  83. if (bSoundOn)
  84. MessageBeep(MB_ICONSTOP);
  85. MessageBox(s1, s2, MB_ICONSTOP); // potential reentrancy problem
  86. }
  87. PostMessage(WM_CLOSE);
  88. }
  89. /****************************************************************************
  90. CMainWindow::GameOver
  91. ****************************************************************************/
  92. void CMainWindow::GameOver()
  93. {
  94. CClientDC dc(this);
  95. #ifdef USE_MIRRORING
  96. SetLayout(dc.m_hDC, 0);
  97. SetLayout(dc.m_hAttribDC, 0);
  98. #endif
  99. InvalidateRect(NULL, TRUE);
  100. p[0]->SetMode(STARTING);
  101. p[0]->SetScore(0);
  102. for (int i = 1; i < MAXPLAYER; i++)
  103. {
  104. delete p[i];
  105. p[i] = NULL;
  106. }
  107. if (role == GAMEMEISTER)
  108. {
  109. p[0]->SetStatus(IDS_GMWAIT);
  110. p[0]->DisplayName(dc);
  111. CMenu *pMenu = GetMenu();
  112. pMenu->EnableMenuItem(IDM_NEWGAME, MF_ENABLED);
  113. PostMessage(WM_COMMAND, IDM_NEWGAME);
  114. return;
  115. }
  116. }