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.

558 lines
15 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. dlg.cpp
  7. Aug 92, JimH
  8. May 93, JimH chico port
  9. Dialog classes are defined here.
  10. CScoreDlg shows current score sheet
  11. CQuoteDlg quote dialog
  12. CWelcomeDlg welcome to Hearts, wanna be gamemeister?
  13. COptionsDlg set options
  14. CLocateDlg locate dealer
  15. ****************************************************************************/
  16. #include "hearts.h"
  17. #include "resource.h"
  18. #include "main.h"
  19. #include "debug.h"
  20. #include "helpnum.h"
  21. #include "stdlib.h"
  22. typedef int (CALLBACK* FPROC)(); // a FARPROC that returns int
  23. // declare statics
  24. int CScoreDlg::nHandsPlayed = 0;
  25. int CScoreDlg::score[MAXPLAYER][MAXHANDS+1];
  26. BOOL CScoreDlg::bGameOver = FALSE;
  27. BEGIN_MESSAGE_MAP( CScoreDlg, CModalDialog )
  28. ON_WM_PAINT()
  29. END_MESSAGE_MAP()
  30. /****************************************************************************
  31. CScoreDlg constructors
  32. The first constructor takes only one argument, the pointer to the class
  33. of the parent window. It is used to display the current score at
  34. arbitrary points in the game, ie when the user requests it.
  35. The second also updates the static score array with new information.
  36. ****************************************************************************/
  37. CScoreDlg::CScoreDlg(CWnd *pParent) : CModalDialog(DLG_SCORE, pParent),
  38. m_myid(-1)
  39. {
  40. }
  41. CScoreDlg::CScoreDlg(CWnd *pParent, int s[MAXPLAYER], int id) :
  42. CModalDialog(DLG_SCORE, pParent), m_myid(id)
  43. {
  44. if (nHandsPlayed == MAXHANDS)
  45. {
  46. for (int hand = 1; hand < MAXHANDS; hand++)
  47. for (int player = 0; player < MAXPLAYER; player++)
  48. score[player][hand-1] = score[player][hand];
  49. nHandsPlayed--;
  50. }
  51. // add latest scores to list
  52. for (int player = 0; player < MAXPLAYER; player++)
  53. score[player][nHandsPlayed] = s[player];
  54. nHandsPlayed++;
  55. }
  56. /****************************************************************************
  57. CScoreDlg::OnInitDialog
  58. ****************************************************************************/
  59. BOOL CScoreDlg::OnInitDialog()
  60. {
  61. RECT rcDlg, rcMain;
  62. GetParent()->GetClientRect(&rcMain);
  63. GetParent()->ClientToScreen(&rcMain);
  64. rcMain.bottom -= ::nStatusHeight;
  65. GetWindowRect(&rcDlg);
  66. int dxDlg = rcDlg.right - rcDlg.left;
  67. int dxMain = rcMain.right - rcMain.left;
  68. int x = rcMain.left + ((dxMain - dxDlg) / 2);
  69. int dyDlg = rcDlg.bottom - rcDlg.top;
  70. int dyMain = rcMain.bottom - rcMain.top;
  71. int y = rcMain.top + ((dyMain - dyDlg) / 2);
  72. SetWindowPos(NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  73. SetText(); // set title bar text
  74. return TRUE;
  75. }
  76. /****************************************************************************
  77. CScoreDlg::SetText -- set title bar text
  78. ****************************************************************************/
  79. void CScoreDlg::SetText()
  80. {
  81. CString s, s2;
  82. s.LoadString(IDS_SCORESHEET);
  83. if (nHandsPlayed != 0)
  84. {
  85. int place = 0;
  86. for (int i = 1; i < MAXPLAYER; i++)
  87. if (score[i][nHandsPlayed-1] < score[0][nHandsPlayed-1])
  88. place++;
  89. s2.LoadString(IDS_PLACE1 + place);
  90. s += " -- ";
  91. s += s2;
  92. }
  93. SetWindowText(s);
  94. }
  95. /****************************************************************************
  96. CScoreDlg::OnPaint
  97. The score text is not drawn with text controls because the strikeout
  98. text is needed for some parts of the score. Instead, the paint message
  99. is hooked here.
  100. ****************************************************************************/
  101. void CScoreDlg::OnPaint()
  102. {
  103. BYTE charset = 0;
  104. int fontsize = 0;
  105. CString fontname, charsetstr, fontsizestr;
  106. fontname.LoadString(IDS_FONTFACE);
  107. charsetstr.LoadString(IDS_CHARSET);
  108. fontsizestr.LoadString(IDS_FONTSIZE);
  109. charset = (BYTE)_ttoi((const TCHAR *)charsetstr);
  110. fontsize = _ttoi((const TCHAR *)fontsizestr);
  111. // Nobody has best score if game hasn't started yet
  112. int nBestScore = (nHandsPlayed == 0 ? 0 : 30000);
  113. int nWorstScore = 0;
  114. if (nHandsPlayed > 0)
  115. {
  116. for (int pos = 0; pos < MAXPLAYER; pos++)
  117. {
  118. if (score[pos][nHandsPlayed-1] < nBestScore)
  119. {
  120. nBestScore = score[pos][nHandsPlayed-1];
  121. }
  122. if (score[pos][nHandsPlayed-1] > nWorstScore)
  123. {
  124. nWorstScore = score[pos][nHandsPlayed-1];
  125. }
  126. }
  127. }
  128. // If the game is over, display appropriate text in title bar
  129. if (nWorstScore >= 100)
  130. {
  131. CString title;
  132. if (score[0][nHandsPlayed-1] == nBestScore)
  133. title.LoadString(IDS_GAMEOVERWIN);
  134. else
  135. title.LoadString(IDS_GAMEOVER);
  136. SetWindowText(title);
  137. bGameOver = TRUE;
  138. }
  139. CPaintDC dc(this);
  140. CRect rect;
  141. GetClientRect(&rect);
  142. // Divide the dialog up into columns for displaying scores
  143. rect.right -= 5; // 5 pixels on left, overlap on right
  144. int nWidth = rect.right / 5;
  145. rect.bottom -= 10; // 5 pixels on top and bottom
  146. int nHeight = rect.bottom;
  147. CString text, s;
  148. dc.SetBkMode(TRANSPARENT);
  149. // If game is over, change the appearance of the dialog so people
  150. // notice it. The section below adds the icon under the OK button.
  151. if (bGameOver)
  152. {
  153. HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(),
  154. MAKEINTRESOURCE(AFX_IDI_STD_FRAME));
  155. int x = (nWidth * 4) + ((nWidth - 32) / 2);
  156. int y = 75;
  157. dc.DrawIcon(x, y, hIcon);
  158. // CRect rectIcon(x-10, y-10, x+32+10, y+32+10);
  159. // FrameRect(rectIcon);
  160. }
  161. // create Helv 8 bold font, and Helv 8 bold strikeout font
  162. CFont font, strikefont;
  163. font.CreateFont(fontsize, 0, 0, 0, 700, 0, 0, 0, charset, 0, 0, 0, 0, fontname);
  164. strikefont.CreateFont(fontsize, 0, 0, 0, 700, 0, 0, 1, charset, 0, 0, 0, 0, fontname);
  165. CFont *oldfont = dc.SelectObject(&font);
  166. for (int pos = 0; pos < MAXPLAYER; pos++)
  167. {
  168. int red = 127; // ega needed special processing here
  169. if (nHandsPlayed > 0)
  170. if (score[pos][nHandsPlayed-1] == nBestScore)
  171. dc.SetTextColor(bGameOver ? RGB(red, 0, 0) : RGB(0, 0, 255));
  172. text = ((CMainWindow *)::pMainWnd)->GetPlayerName(pos);
  173. // The line below allows overlapping of names at top of score dlg.
  174. // To disallow overlapping, use:
  175. // rect.SetRect(5 + (nWidth*pos), 5, 5 + (nWidth*(pos+1)), nHeight);
  176. rect.SetRect((nWidth*pos) - 5, 5, 15 + (nWidth*(pos+1)), nHeight);
  177. int nTextHeight = dc.DrawText(text, -1, &rect, DT_CENTER | DT_NOPREFIX);
  178. rect.top += nTextHeight;
  179. dc.SelectObject(&strikefont);
  180. text.Empty();
  181. for (int hand = 0; hand < (nHandsPlayed - 1); hand++)
  182. {
  183. wsprintf(s.GetBuffer(20), TEXT("%d\r\n"), score[pos][hand]);
  184. s.ReleaseBuffer();
  185. text += s;
  186. }
  187. dc.DrawText(text, -1, &rect, DT_CENTER);
  188. rect.top += (nTextHeight * (nHandsPlayed - 1));
  189. dc.SelectObject(&font);
  190. if (nHandsPlayed > 0)
  191. {
  192. wsprintf(text.GetBuffer(20), TEXT("%d"), score[pos][nHandsPlayed-1]);
  193. text.ReleaseBuffer();
  194. }
  195. dc.DrawText(text, -1, &rect, DT_CENTER);
  196. dc.SetTextColor(0);
  197. }
  198. dc.SelectObject(oldfont);
  199. }
  200. /****************************************************************************
  201. CQuoteDlg
  202. ****************************************************************************/
  203. BEGIN_MESSAGE_MAP( CQuoteDlg, CModalDialog )
  204. ON_WM_PAINT()
  205. END_MESSAGE_MAP()
  206. /****************************************************************************
  207. CQuoteDlg constructor
  208. ****************************************************************************/
  209. CQuoteDlg::CQuoteDlg(CWnd *pParent) : CModalDialog(DLG_QUOTE, pParent)
  210. {
  211. }
  212. /****************************************************************************
  213. CQuoteDlg::OnPaint
  214. This used to draw an icon and a 3d frame. Now it just draws the icon.
  215. ****************************************************************************/
  216. void CQuoteDlg::OnPaint()
  217. {
  218. CPaintDC dc(this);
  219. #ifdef USE_MIRRORING
  220. SetLayout(dc.m_hDC, 0);
  221. SetLayout(dc.m_hAttribDC, 0);
  222. #endif
  223. HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(),
  224. MAKEINTRESOURCE(AFX_IDI_STD_FRAME));
  225. int x = 24;
  226. int y = 24;
  227. dc.DrawIcon(x, y, hIcon);
  228. // CRect rectIcon(x-10, y-10, x+32+10, y+32+10);
  229. // FrameRect(rectIcon);
  230. }
  231. /****************************************************************************
  232. CWelcomeDlg
  233. ****************************************************************************/
  234. BEGIN_MESSAGE_MAP( CWelcomeDlg, CModalDialog )
  235. ON_BN_CLICKED(IDC_WELCOMEHELP, OnHelp)
  236. END_MESSAGE_MAP()
  237. /****************************************************************************
  238. CWelcomeDlg constructor
  239. ****************************************************************************/
  240. CWelcomeDlg::CWelcomeDlg(CWnd *pParent) : CModalDialog(DLG_WELCOME, pParent),
  241. m_bGameMeister(FALSE)
  242. {
  243. RegEntry Reg(szRegPath);
  244. TCHAR *pm_myname = m_myname.GetBuffer(MAXNAMELENGTH+1);
  245. Reg.GetString(regvalName, pm_myname, MAXNAMELENGTH+1);
  246. m_myname.ReleaseBuffer();
  247. }
  248. /****************************************************************************
  249. CWelcomeDlg::OnInitDialog()
  250. Restore settings from .ini file
  251. ****************************************************************************/
  252. BOOL CWelcomeDlg::OnInitDialog()
  253. {
  254. CEdit *editname = (CEdit *)GetDlgItem(IDC_YOURNAME);
  255. editname->SetWindowText(m_myname);
  256. editname->LimitText(MAXNAMELENGTH);
  257. return TRUE;
  258. }
  259. /****************************************************************************
  260. CWelcomeDlg::OnOK()
  261. Don't allow empty name. Store data in .ini file.
  262. ****************************************************************************/
  263. void CWelcomeDlg::OnOK()
  264. {
  265. GetDlgItemText(IDC_YOURNAME, m_myname.GetBuffer(MAXNAMELENGTH+1),
  266. MAXNAMELENGTH+1);
  267. m_myname.ReleaseBuffer();
  268. if (m_myname.IsEmpty())
  269. {
  270. ((CEdit *)GetDlgItem(IDC_YOURNAME))->SetFocus();
  271. return;
  272. }
  273. m_bGameMeister = TRUE;
  274. RegEntry Reg(szRegPath);
  275. Reg.SetValue(regvalRole, m_bGameMeister ? 1 : 0L);
  276. Reg.SetValue(regvalName, m_myname);
  277. // ::WinHelp(m_hWnd, szHelpFileName, HELP_QUIT, 0);
  278. EndDialog(IDOK);
  279. }
  280. /****************************************************************************
  281. CWelcomeDlg::OnHelp()
  282. ****************************************************************************/
  283. void CWelcomeDlg::OnHelp()
  284. {
  285. // ::WinHelp(m_hWnd, szHelpFileName, HELP_CONTEXT, IDH_START_HOW_HRTS);
  286. }
  287. /****************************************************************************
  288. COptionsDlg constructor
  289. ****************************************************************************/
  290. COptionsDlg::COptionsDlg(CWnd *pParent) : CModalDialog(DLG_OPTIONS, pParent)
  291. {
  292. }
  293. /****************************************************************************
  294. COptionsDlg::OnInitDialog
  295. Set dialog controls to current values
  296. ****************************************************************************/
  297. BOOL COptionsDlg::OnInitDialog()
  298. {
  299. RegEntry Reg(szRegPath);
  300. // Set animation speed radio button
  301. DWORD dwSpeed = Reg.GetNumber(regvalSpeed, IDC_NORMAL);
  302. ((CButton *)GetDlgItem((int)dwSpeed))->SetCheck(TRUE);
  303. // Set current computer player names. If they are not specified in
  304. // the .ini file, get defaults from the resource file.
  305. CEdit *pName[3];
  306. CString sName[3];
  307. for (int i = 0; i < 3; i++)
  308. {
  309. pName[i] = (CEdit *)GetDlgItem(IDC_NAME1 + i);
  310. pName[i]->LimitText(MAXNAMELENGTH);
  311. TCHAR *p = sName[i].GetBuffer(MAXNAMELENGTH + 1);
  312. Reg.GetString(regvalPName[i], p, MAXNAMELENGTH+1);
  313. sName[i].ReleaseBuffer();
  314. if (sName[i].IsEmpty())
  315. sName[i].LoadString(IDS_P1NAME + i);
  316. pName[i]->SetWindowText(p);
  317. }
  318. // get current autostart state
  319. m_bInitialState = IsAutoStart();
  320. // ((CButton *)GetDlgItem(IDC_AUTO))->SetCheck(m_bInitialState);
  321. return TRUE;
  322. }
  323. /****************************************************************************
  324. COptionsDlg::OnOK
  325. save contol settings
  326. ****************************************************************************/
  327. void COptionsDlg::OnOK()
  328. {
  329. RegEntry Reg(szRegPath);
  330. // save animation speed setting
  331. DWORD dwSpeed;
  332. int nStepSize;
  333. if (((CButton *)GetDlgItem(IDC_FAST))->GetCheck())
  334. {
  335. dwSpeed = IDC_FAST;
  336. nStepSize = 60;
  337. }
  338. else if (((CButton *)GetDlgItem(IDC_SLOW))->GetCheck())
  339. {
  340. dwSpeed = IDC_SLOW;
  341. nStepSize = 5;
  342. }
  343. else
  344. {
  345. dwSpeed = IDC_NORMAL;
  346. nStepSize = 15;
  347. }
  348. card c;
  349. c.SetStepSize(nStepSize);
  350. Reg.SetValue(regvalSpeed, dwSpeed);
  351. // save computer player names
  352. for (int i = 0; i < 3; i++)
  353. {
  354. CString sDefault, sEdit;
  355. sDefault.LoadString(IDS_P1NAME + i);
  356. GetDlgItemText(IDC_NAME1 + i, sEdit.GetBuffer(MAXNAMELENGTH+1),
  357. MAXNAMELENGTH+1);
  358. sEdit.ReleaseBuffer();
  359. if (sDefault == sEdit)
  360. Reg.DeleteValue(regvalPName[i]);
  361. else
  362. Reg.SetValue(regvalPName[i], sEdit);
  363. }
  364. // save autostart state
  365. // BOOL bState = ((CButton *)GetDlgItem(IDC_AUTO))->GetCheck();
  366. // if (bState != m_bInitialState)
  367. // IsAutoStart(TRUE); // toggle state
  368. EndDialog(IDOK);
  369. }
  370. /****************************************************************************
  371. COptionsDlg::IsAutoStart
  372. returns autostart state, and optionally toggles it. The bToggle
  373. parameter is FALSE by default.
  374. If bToggle is TRUE, this function returns the NEW state.
  375. ****************************************************************************/
  376. BOOL COptionsDlg::IsAutoStart(BOOL bToggle)
  377. {
  378. return FALSE;
  379. }