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.

1044 lines
22 KiB

  1. /****************************************************************************
  2. PROGRAM: WinMine (a.k.a. Mines, BombSquad, MineSweeper...)
  3. ****************************************************************************/
  4. #define _WINDOWS
  5. #include <windows.h>
  6. #include <port1632.h>
  7. #include <htmlhelp.h> // for HtmlHelp()
  8. #include <commctrl.h> // for fusion classes.
  9. #include "main.h"
  10. #include "rtns.h"
  11. #include "grafix.h"
  12. #include "res.h"
  13. #include "pref.h"
  14. #include "util.h"
  15. #include "sound.h"
  16. #include "context.h"
  17. #include "string.h"
  18. #include "stdio.h"
  19. #include "dos.h"
  20. #ifndef WM_ENTERMENULOOP
  21. #define WM_ENTERMENULOOP 0x0211
  22. #define WM_EXITMENULOOP 0x0212
  23. #endif
  24. BOOL bInitMinimized; /* Bug #13328: HACK! Don't permit MoveWindow or */
  25. /* InvalidateRect when initially minimized. */
  26. /* 19 September 1991 Clark R. Cyr */
  27. HANDLE hInst;
  28. HWND hwndMain;
  29. HMENU hMenu;
  30. // Icon handles to load the winmine icon.
  31. HICON hIconMain;
  32. BOOL fButton1Down = fFalse;
  33. BOOL fBlock = fFalse;
  34. BOOL fIgnoreClick = fFalse;
  35. INT dypCaption;
  36. INT dypMenu;
  37. INT dypBorder;
  38. INT dxpBorder;
  39. INT fStatus = (fDemo + fIcon);
  40. BOOL fLocalPause = fFalse;
  41. TCHAR szClass[cchNameMax];
  42. #define szWindowTitle szClass
  43. TCHAR szTime[cchNameMax];
  44. TCHAR szDefaultName[cchNameMax];
  45. extern BOOL fUpdateIni;
  46. extern INT xCur;
  47. extern INT yCur;
  48. extern INT iButtonCur;
  49. extern INT xBoxMac;
  50. extern INT yBoxMac;
  51. extern PREF Preferences;
  52. extern INT cBoxVisit;
  53. INT dxWindow;
  54. INT dyWindow;
  55. INT dypCaption;
  56. INT dypMenu;
  57. INT dypAdjust;
  58. INT idRadCurr = 0;
  59. #define iPrefMax 3
  60. #define idRadMax 3
  61. INT rgPrefEditID[iPrefMax] =
  62. {ID_EDIT_MINES, ID_EDIT_HEIGHT, ID_EDIT_WIDTH};
  63. INT rgLevelData[idRadMax][iPrefMax] = {
  64. {10, MINHEIGHT, MINWIDTH, },
  65. {40, 16, 16,},
  66. {99, 16, 30,}
  67. };
  68. #ifndef DEBUG
  69. #define XYZZY
  70. #define cchXYZZY 5
  71. INT iXYZZY = 0;
  72. TCHAR szXYZZY[cchXYZZY+1] = TEXT("XYZZY");
  73. extern CHAR rgBlk[cBlkMax];
  74. #endif
  75. LRESULT APIENTRY MainWndProc(HWND, UINT, WPARAM, LPARAM);
  76. INT_PTR APIENTRY PrefDlgProc(HWND, UINT, WPARAM, LPARAM);
  77. INT_PTR APIENTRY BestDlgProc(HWND, UINT, WPARAM, LPARAM);
  78. INT_PTR APIENTRY EnterDlgProc(HWND, UINT, WPARAM, LPARAM);
  79. /****** W I N M A I N ******/
  80. MMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  81. /* { */
  82. MSG msg;
  83. HANDLE hAccel;
  84. hInst = hInstance;
  85. InitConst();
  86. bInitMinimized = (nCmdShow == SW_SHOWMINNOACTIVE) ||
  87. (nCmdShow == SW_SHOWMINIMIZED) ;
  88. #ifdef WIN16
  89. if (hPrevInstance)
  90. {
  91. HWND hWnd = FindWindow(szClass, NULL);
  92. hWnd = GetLastActivePopup(hWnd);
  93. BringWindowToTop(hWnd);
  94. if (!bInitMinimized && IsIconic(hWnd))
  95. SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L);
  96. return fFalse;
  97. }
  98. #endif
  99. #ifdef NOSERVER /*** Not in final release ***/
  100. {
  101. TCHAR szFile[256];
  102. GetModuleFileName(hInst, szFile, 250);
  103. if (szFile[0] > TEXT('C'))
  104. {
  105. szFile[0] = TEXT('X');
  106. if (!lstrcmp(szFile, TEXT("X:\\WINGAMES\\WINMINE\\WINMINE.EXE")))
  107. {
  108. MessageBox(GetFocus(),
  109. TEXT("Please copy winmine.exe and aboutwep.dll to your machine and run it from there."),
  110. TEXT("NO NO NO NO NO"),
  111. MB_OK);
  112. return fFalse;
  113. }
  114. }
  115. }
  116. #endif
  117. #ifdef EXPIRE /*** Not in final release ***/
  118. {
  119. struct dosdate_t ddt;
  120. _dos_getdate(&ddt);
  121. if ((ddt.month + ddt.year*12) > (9 + 1990*12))
  122. {
  123. MessageBox(GetFocus(),
  124. TEXT("This game has expired. Please obtain an official copy from the Windows Entertainment Package."),
  125. TEXT("SORRY"),
  126. MB_OK);
  127. return fFalse;
  128. }
  129. }
  130. #endif
  131. {
  132. WNDCLASS wc;
  133. INITCOMMONCONTROLSEX icc; // common control registration.
  134. // Register the common controls.
  135. icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
  136. icc.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_HOTKEY_CLASS | ICC_LISTVIEW_CLASSES |
  137. ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS | ICC_TAB_CLASSES | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES;
  138. InitCommonControlsEx(&icc);
  139. hIconMain = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_MAIN));
  140. wc.style = 0;
  141. wc.lpfnWndProc = MainWndProc;
  142. wc.cbClsExtra = 0;
  143. wc.cbWndExtra = 0;
  144. wc.hInstance = hInst;
  145. wc.hIcon = hIconMain;
  146. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  147. wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  148. wc.lpszMenuName = NULL;
  149. wc.lpszClassName = szClass;
  150. if (!RegisterClass(&wc))
  151. return fFalse;
  152. }
  153. hMenu = LoadMenu(hInst, MAKEINTRESOURCE(ID_MENU));
  154. hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(ID_MENU_ACCEL));
  155. ReadPreferences();
  156. hwndMain = CreateWindow( szClass, szWindowTitle,
  157. WS_OVERLAPPED | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU,
  158. Preferences.xWindow-dxpBorder, Preferences.yWindow-dypAdjust,
  159. dxWindow+dxpBorder, dyWindow +dypAdjust,
  160. NULL, NULL, hInst, NULL);
  161. if (!hwndMain)
  162. {
  163. ReportErr(1000);
  164. return fFalse;
  165. }
  166. AdjustWindow(fCalc);
  167. if (!FInitLocal())
  168. {
  169. ReportErr(ID_ERR_MEM);
  170. return fFalse;
  171. }
  172. SetMenuBar(Preferences.fMenu);
  173. StartGame();
  174. ShowWindow(hwndMain, SW_SHOWNORMAL);
  175. UpdateWindow(hwndMain);
  176. bInitMinimized = FALSE;
  177. while (GetMessage(&msg, NULL, 0, 0))
  178. {
  179. if (!TranslateAccelerator(hwndMain, hAccel, &msg))
  180. {
  181. TranslateMessage(&msg);
  182. DispatchMessage(&msg);
  183. }
  184. }
  185. CleanUp();
  186. if (fUpdateIni)
  187. WritePreferences();
  188. return ((INT) msg.wParam);
  189. }
  190. /****** F L O C A L B U T T O N ******/
  191. BOOL FLocalButton(LPARAM lParam)
  192. {
  193. BOOL fDown = fTrue;
  194. RECT rcCapt;
  195. MSG msg;
  196. msg.pt.x = LOWORD(lParam);
  197. msg.pt.y = HIWORD(lParam);
  198. rcCapt.right = dxButton + (rcCapt.left = (dxWindow-dxButton) >> 1);
  199. rcCapt.bottom = dyButton + (rcCapt.top = dyTopLed);
  200. if (!PtInRect(&rcCapt, msg.pt))
  201. return fFalse;
  202. SetCapture(hwndMain);
  203. DisplayButton(iButtonDown);
  204. MapWindowPoints(hwndMain , NULL , (LPPOINT) &rcCapt , 2);
  205. while (fTrue)
  206. {
  207. if (PeekMessage(&msg, hwndMain, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  208. {
  209. switch (msg.message)
  210. {
  211. case WM_LBUTTONUP:
  212. if (fDown)
  213. {
  214. if (PtInRect(&rcCapt, msg.pt))
  215. {
  216. DisplayButton(iButtonCur = iButtonHappy);
  217. StartGame();
  218. }
  219. }
  220. ReleaseCapture();
  221. return fTrue;
  222. case WM_MOUSEMOVE:
  223. if (PtInRect(&rcCapt, msg.pt))
  224. {
  225. if (!fDown)
  226. {
  227. fDown = fTrue;
  228. DisplayButton(iButtonDown);
  229. }
  230. }
  231. else
  232. {
  233. if (fDown)
  234. {
  235. fDown = fFalse;
  236. DisplayButton(iButtonCur);
  237. }
  238. }
  239. default:
  240. ;
  241. } /* switch */
  242. }
  243. } /* while */
  244. }
  245. /****** F I X M E N U S ******/
  246. VOID FixMenus(VOID)
  247. {
  248. CheckEm(IDM_BEGIN, Preferences.wGameType == wGameBegin);
  249. CheckEm(IDM_INTER, Preferences.wGameType == wGameInter);
  250. CheckEm(IDM_EXPERT, Preferences.wGameType == wGameExpert);
  251. CheckEm(IDM_CUSTOM, Preferences.wGameType == wGameOther);
  252. CheckEm(IDM_COLOR, Preferences.fColor);
  253. CheckEm(IDM_MARK, Preferences.fMark);
  254. CheckEm(IDM_SOUND, Preferences.fSound);
  255. }
  256. /****** D O P R E F ******/
  257. VOID DoPref(VOID)
  258. {
  259. DialogBox(hInst, MAKEINTRESOURCE(ID_DLG_PREF), hwndMain, PrefDlgProc);
  260. Preferences.wGameType = wGameOther;
  261. FixMenus();
  262. fUpdateIni = fTrue;
  263. StartGame();
  264. }
  265. /****** D O E N T E R N A M E ******/
  266. VOID DoEnterName(VOID)
  267. {
  268. DialogBox(hInst, MAKEINTRESOURCE(ID_DLG_ENTER), hwndMain, EnterDlgProc);
  269. fUpdateIni = fTrue;
  270. }
  271. /****** D O D I S P L A Y B E S T ******/
  272. VOID DoDisplayBest(VOID)
  273. {
  274. DialogBox(hInst, MAKEINTRESOURCE(ID_DLG_BEST), hwndMain, BestDlgProc);
  275. }
  276. /****** M A I N W N D P R O C ******/
  277. LRESULT APIENTRY MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  278. {
  279. switch (message)
  280. {
  281. case WM_WINDOWPOSCHANGED:
  282. if (!fStatusIcon)
  283. {
  284. Preferences.xWindow = ((LPWINDOWPOS) (lParam))->x;
  285. Preferences.yWindow = ((LPWINDOWPOS) (lParam))->y;
  286. }
  287. break;
  288. case WM_SYSCOMMAND:
  289. switch (wParam & 0xFFF0)
  290. {
  291. case SC_MINIMIZE:
  292. PauseGame();
  293. SetStatusPause;
  294. SetStatusIcon;
  295. break;
  296. case SC_RESTORE:
  297. ClrStatusPause;
  298. ClrStatusIcon;
  299. ResumeGame();
  300. //Japan Bug fix: 1/19/93 Enable the first click after restoring from icon.
  301. fIgnoreClick = fFalse;
  302. break;
  303. default:
  304. break;
  305. }
  306. break;
  307. case WM_COMMAND:
  308. {
  309. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  310. case IDM_NEW:
  311. StartGame();
  312. break;
  313. /** IDM_NEW **/
  314. case IDM_EXIT:
  315. ShowWindow(hwndMain, SW_HIDE);
  316. #ifdef ORGCODE
  317. goto LExit;
  318. #else
  319. SendMessage(hwndMain, WM_SYSCOMMAND, SC_CLOSE, 0);
  320. return(0);
  321. #endif
  322. /** IDM_SKILL **/
  323. case IDM_BEGIN:
  324. case IDM_INTER:
  325. case IDM_EXPERT:
  326. Preferences.wGameType = (WORD)(GET_WM_COMMAND_ID(wParam, lParam) - IDM_BEGIN);
  327. Preferences.Mines = rgLevelData[Preferences.wGameType][0];
  328. Preferences.Height = rgLevelData[Preferences.wGameType][1];
  329. Preferences.Width = rgLevelData[Preferences.wGameType][2];
  330. StartGame();
  331. goto LUpdateMenu;
  332. case IDM_CUSTOM:
  333. DoPref();
  334. break;
  335. /** IDM_OPTIONS **/
  336. case IDM_SOUND:
  337. if (Preferences.fSound)
  338. {
  339. EndTunes();
  340. Preferences.fSound = fFalse;
  341. }
  342. else
  343. {
  344. Preferences.fSound = FInitTunes();
  345. }
  346. goto LUpdateMenu;
  347. case IDM_COLOR:
  348. Preferences.fColor = !Preferences.fColor;
  349. FreeBitmaps();
  350. if (!FLoadBitmaps())
  351. {
  352. ReportErr(ID_ERR_MEM);
  353. #ifdef ORGCODE
  354. goto LExit;
  355. #else
  356. SendMessage(hwndMain, WM_SYSCOMMAND, SC_CLOSE, 0);
  357. return(0);
  358. #endif
  359. }
  360. DisplayScreen();
  361. goto LUpdateMenu;
  362. case IDM_MARK:
  363. Preferences.fMark = !Preferences.fMark;
  364. /* IE goto LUpdateMenu; */
  365. LUpdateMenu:
  366. fUpdateIni = fTrue;
  367. SetMenuBar(Preferences.fMenu);
  368. break;
  369. case IDM_BEST:
  370. DoDisplayBest();
  371. break;
  372. /** IDM_HELP **/
  373. case IDM_HELP:
  374. DoHelp(HELP_INDEX, HH_DISPLAY_TOPIC);
  375. break;
  376. case IDM_HOW2PLAY:
  377. DoHelp(HELP_CONTEXT, HH_DISPLAY_INDEX);
  378. break;
  379. case IDM_HELP_HELP:
  380. DoHelp(HELP_HELPONHELP, HH_DISPLAY_TOPIC);
  381. break;
  382. case IDM_HELP_ABOUT:
  383. DoAbout();
  384. return 0;
  385. default:
  386. break;
  387. }
  388. } /**** END OF MENUS ****/
  389. break;
  390. case WM_KEYDOWN:
  391. switch (wParam)
  392. {
  393. #if 0
  394. case VK_F1:
  395. DoHelp(HELP_INDEX, 0L);
  396. break;
  397. case VK_F2:
  398. StartGame();
  399. break;
  400. case VK_F3:
  401. break;
  402. #endif
  403. case VK_F4:
  404. if (FSoundSwitchable())
  405. if (FSoundOn())
  406. {
  407. EndTunes();
  408. Preferences.fSound = fsoundOff;
  409. }
  410. else
  411. Preferences.fSound = FInitTunes();
  412. break;
  413. case VK_F5:
  414. if (FMenuSwitchable())
  415. SetMenuBar(fmenuOff);
  416. break;
  417. case VK_F6:
  418. if (FMenuSwitchable())
  419. SetMenuBar(fmenuOn);
  420. break;
  421. #ifdef XYZZY
  422. case VK_SHIFT:
  423. if (iXYZZY >= cchXYZZY)
  424. iXYZZY ^= 20;
  425. break;
  426. default:
  427. if (iXYZZY < cchXYZZY)
  428. iXYZZY = (szXYZZY[iXYZZY] == (TCHAR) wParam) ? iXYZZY+1 : 0;
  429. break;
  430. #else
  431. default:
  432. break;
  433. #endif
  434. }
  435. break;
  436. /* case WM_QUERYENDSESSION: SHOULDNT BE USED (JAP)*/
  437. case WM_DESTROY:
  438. //LExit:
  439. KillTimer(hwndMain, ID_TIMER);
  440. PostQuitMessage(0);
  441. break;
  442. case WM_MBUTTONDOWN:
  443. if (fIgnoreClick)
  444. {
  445. fIgnoreClick = fFalse;
  446. return 0;
  447. }
  448. if (!fStatusPlay)
  449. break;
  450. fBlock = fTrue;
  451. goto LBigStep;
  452. case WM_LBUTTONDOWN:
  453. if (fIgnoreClick)
  454. {
  455. fIgnoreClick = fFalse;
  456. return 0;
  457. }
  458. if (FLocalButton(lParam))
  459. return 0;
  460. if (!fStatusPlay)
  461. break;
  462. fBlock = (wParam & (MK_SHIFT | MK_RBUTTON)) ? fTrue : fFalse;
  463. LBigStep:
  464. SetCapture(hWnd);
  465. fButton1Down = fTrue;
  466. xCur = -1;
  467. yCur = -1;
  468. DisplayButton(iButtonCaution);
  469. case WM_MOUSEMOVE:
  470. if (fButton1Down)
  471. {
  472. if (fStatus & fPlay)
  473. TrackMouse(xBoxFromXpos(LOWORD(lParam)), yBoxFromYpos(HIWORD(lParam)) );
  474. else
  475. goto LFixTimeOut;
  476. }
  477. #ifdef XYZZY
  478. //
  479. // This is the cheat:
  480. // If you hold down the shift key and type 'XYZZY'
  481. // then when you hold down the control key, to upper
  482. // left hand corner pixel will show the state of the
  483. // mine field under the mouse. Oh. joy. I can win.
  484. //
  485. else if (iXYZZY != 0)
  486. if (((iXYZZY == cchXYZZY) && (wParam & MK_CONTROL))
  487. ||(iXYZZY > cchXYZZY))
  488. {
  489. xCur = xBoxFromXpos(LOWORD(lParam));
  490. yCur = yBoxFromYpos(HIWORD(lParam));
  491. if (fInRange(xCur, yCur))
  492. {
  493. HDC hDC = GetDC(NULL);
  494. SetPixel(hDC, 0, 0, fISBOMB(xCur, yCur) ? 0L : 0x00FFFFFFL);
  495. ReleaseDC(NULL, hDC);
  496. }
  497. }
  498. #endif
  499. break;
  500. case WM_RBUTTONUP:
  501. case WM_MBUTTONUP:
  502. case WM_LBUTTONUP:
  503. if (fButton1Down)
  504. {
  505. LFixTimeOut:
  506. fButton1Down = fFalse;
  507. ReleaseCapture();
  508. if (fStatus & fPlay)
  509. DoButton1Up();
  510. else
  511. TrackMouse(-2,-2);
  512. }
  513. break;
  514. case WM_RBUTTONDOWN:
  515. if (fIgnoreClick)
  516. {
  517. fIgnoreClick = fFalse;
  518. return 0;
  519. }
  520. if(!fStatusPlay)
  521. break;
  522. if (fButton1Down)
  523. {
  524. TrackMouse(-3,-3);
  525. fBlock = fTrue;
  526. PostMessage(hwndMain, WM_MOUSEMOVE, wParam, lParam);
  527. }
  528. else if (wParam & MK_LBUTTON)
  529. goto LBigStep;
  530. else if (!fLocalPause)
  531. MakeGuess(xBoxFromXpos(LOWORD(lParam)), yBoxFromYpos(HIWORD(lParam)) );
  532. return 0;
  533. case WM_ACTIVATE:
  534. /* Window is being activated by a mouse click */
  535. if (GET_WM_ACTIVATE_STATE(wParam, lParam) == 2)
  536. fIgnoreClick = fTrue;
  537. break;
  538. case WM_TIMER:
  539. #ifdef CHEAT
  540. if (!fLocalPause)
  541. #endif
  542. DoTimer();
  543. return 0;
  544. case WM_ENTERMENULOOP:
  545. fLocalPause = fTrue;
  546. break;
  547. case WM_EXITMENULOOP:
  548. fLocalPause = fFalse;
  549. break;
  550. case WM_PAINT:
  551. {
  552. PAINTSTRUCT ps;
  553. HDC hDC = BeginPaint(hWnd,&ps);
  554. DrawScreen(hDC);
  555. EndPaint(hWnd, &ps);
  556. }
  557. return 0;
  558. default:
  559. break;
  560. }
  561. return (DefWindowProc(hWnd, message, wParam, lParam));
  562. }
  563. /****** DIALOG PROCEDURES ******/
  564. /*** P R E F D L G P R O C ***/
  565. INT_PTR APIENTRY PrefDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  566. {
  567. // for context sensitive help
  568. static DWORD aIds[] = {
  569. ID_EDIT_HEIGHT, IDH_PREF_EDIT_HEIGHT,
  570. ID_EDIT_WIDTH, IDH_PREF_EDIT_WIDTH,
  571. ID_EDIT_MINES, IDH_PREF_EDIT_MINES,
  572. ID_TXT_HEIGHT, IDH_PREF_EDIT_HEIGHT,
  573. ID_TXT_WIDTH, IDH_PREF_EDIT_WIDTH,
  574. ID_TXT_MINES, IDH_PREF_EDIT_MINES,
  575. 0,0 };
  576. switch (message)
  577. {
  578. case WM_INITDIALOG:
  579. SetDlgItemInt(hDlg, ID_EDIT_HEIGHT, Preferences.Height ,fFalse);
  580. SetDlgItemInt(hDlg, ID_EDIT_WIDTH, Preferences.Width ,fFalse);
  581. SetDlgItemInt(hDlg, ID_EDIT_MINES, Preferences.Mines ,fFalse);
  582. return (fTrue);
  583. case WM_COMMAND:
  584. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  585. case ID_BTN_OK:
  586. case IDOK:
  587. {
  588. Preferences.Height = GetDlgInt(hDlg, ID_EDIT_HEIGHT, MINHEIGHT, 24);
  589. Preferences.Width = GetDlgInt(hDlg, ID_EDIT_WIDTH, MINWIDTH, 30);
  590. Preferences.Mines = GetDlgInt(hDlg, ID_EDIT_MINES, 10,
  591. min(999, (Preferences.Height-1) * (Preferences.Width-1) ) );
  592. }
  593. /* Fall Through & Exit */
  594. case ID_BTN_CANCEL:
  595. case IDCANCEL:
  596. EndDialog(hDlg, fTrue); /* Exits the dialog box */
  597. return fTrue;
  598. default:
  599. break;
  600. }
  601. break;
  602. // context sensitive help.
  603. case WM_HELP:
  604. WinHelp(((LPHELPINFO) lParam)->hItemHandle, TEXT("winmine.hlp"),
  605. HELP_WM_HELP, (ULONG_PTR) aIds);
  606. break;
  607. case WM_CONTEXTMENU:
  608. WinHelp((HWND) wParam, TEXT("winmine.hlp"), HELP_CONTEXTMENU,
  609. (ULONG_PTR) aIds);
  610. break;
  611. }
  612. return (fFalse); /* Didn't process a message */
  613. }
  614. /*** S E T D T E X T ***/
  615. VOID SetDText(HWND hDlg, INT id, INT time, TCHAR FAR * szName)
  616. {
  617. TCHAR sz[cchNameMax];
  618. wsprintf(sz, szTime, time);
  619. SetDlgItemText(hDlg, id, sz);
  620. SetDlgItemText(hDlg, id+1, szName);
  621. }
  622. /****** B E S T D L G P R O C ******/
  623. INT_PTR APIENTRY BestDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  624. {
  625. // for context sensitive help
  626. static DWORD aIds[] = {
  627. ID_BTN_RESET, IDH_BEST_BTN_RESET,
  628. ID_STEXT1, IDH_STEXT,
  629. ID_STEXT2, IDH_STEXT,
  630. ID_STEXT3, IDH_STEXT,
  631. ID_TIME_BEGIN, IDH_STEXT,
  632. ID_TIME_INTER, IDH_STEXT,
  633. ID_TIME_EXPERT, IDH_STEXT,
  634. ID_NAME_BEGIN, IDH_STEXT,
  635. ID_NAME_INTER, IDH_STEXT,
  636. ID_NAME_EXPERT, IDH_STEXT,
  637. 0,0 };
  638. switch (message)
  639. {
  640. case WM_INITDIALOG:
  641. LReset:
  642. SetDText(hDlg, ID_TIME_BEGIN, Preferences.rgTime[wGameBegin], Preferences.szBegin);
  643. SetDText(hDlg, ID_TIME_INTER, Preferences.rgTime[wGameInter], Preferences.szInter);
  644. SetDText(hDlg, ID_TIME_EXPERT, Preferences.rgTime[wGameExpert], Preferences.szExpert);
  645. return (fTrue);
  646. case WM_COMMAND:
  647. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  648. case ID_BTN_RESET:
  649. Preferences.rgTime[wGameBegin] = Preferences.rgTime[wGameInter]
  650. = Preferences.rgTime[wGameExpert] = 999;
  651. lstrcpy(Preferences.szBegin, szDefaultName);
  652. lstrcpy(Preferences.szInter, szDefaultName);
  653. lstrcpy(Preferences.szExpert, szDefaultName);
  654. fUpdateIni = fTrue;
  655. goto LReset;
  656. case ID_BTN_OK:
  657. case IDOK:
  658. case ID_BTN_CANCEL:
  659. case IDCANCEL:
  660. EndDialog(hDlg, fTrue); /* Exits the dialog box */
  661. return fTrue;
  662. default:
  663. break;
  664. }
  665. break;
  666. // context sensitive help.
  667. case WM_HELP:
  668. WinHelp(((LPHELPINFO) lParam)->hItemHandle, TEXT("winmine.hlp"),
  669. HELP_WM_HELP, (ULONG_PTR) aIds);
  670. break;
  671. case WM_CONTEXTMENU:
  672. WinHelp((HWND) wParam, TEXT("winmine.hlp"), HELP_CONTEXTMENU,
  673. (ULONG_PTR) aIds);
  674. break;
  675. }
  676. return (fFalse); /* Didn't process a message */
  677. }
  678. /****** E N T E R D L G P R O C ******/
  679. INT_PTR APIENTRY EnterDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  680. {
  681. switch (message)
  682. {
  683. case WM_INITDIALOG:
  684. {
  685. TCHAR sz[cchMsgMax];
  686. LoadSz((WORD)(Preferences.wGameType+ID_MSG_BEGIN), sz, ARRAYSIZE(sz));
  687. SetDlgItemText(hDlg, ID_TEXT_BEST, sz);
  688. SendMessage(GetDlgItem(hDlg, ID_EDIT_NAME), EM_SETLIMITTEXT, cchNameMax, 0L);
  689. SetDlgItemText(hDlg, ID_EDIT_NAME,
  690. (Preferences.wGameType == wGameBegin) ? Preferences.szBegin :
  691. (Preferences.wGameType == wGameInter) ? Preferences.szInter :
  692. Preferences.szExpert);
  693. }
  694. return (fTrue);
  695. case WM_COMMAND:
  696. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  697. case ID_BTN_OK:
  698. case IDOK:
  699. case ID_BTN_CANCEL:
  700. case IDCANCEL:
  701. GetDlgItemText(hDlg, ID_EDIT_NAME,
  702. (Preferences.wGameType == wGameBegin) ? Preferences.szBegin :
  703. (Preferences.wGameType == wGameInter) ? Preferences.szInter :
  704. Preferences.szExpert, cchNameMax);
  705. EndDialog(hDlg, fTrue); /* Exits the dialog box */
  706. return fTrue;
  707. default:
  708. break;
  709. }
  710. }
  711. return (fFalse); /* Didn't process a message */
  712. (lParam);
  713. }
  714. /****** A D J U S T W I N D O W ******/
  715. // Our verion of GetSystemMetrics
  716. //
  717. // Tries to return whole screen (include other monitor) info
  718. //
  719. INT OurGetSystemMetrics( INT nIndex )
  720. {
  721. INT Result=0;
  722. switch( nIndex )
  723. {
  724. case SM_CXSCREEN:
  725. Result= GetSystemMetrics( SM_CXVIRTUALSCREEN );
  726. if( !Result )
  727. Result= GetSystemMetrics( SM_CXSCREEN );
  728. break;
  729. case SM_CYSCREEN:
  730. Result= GetSystemMetrics( SM_CYVIRTUALSCREEN );
  731. if( !Result )
  732. Result= GetSystemMetrics( SM_CYSCREEN );
  733. break;
  734. default:
  735. Result= GetSystemMetrics( nIndex );
  736. break;
  737. }
  738. return( Result );
  739. }
  740. VOID AdjustWindow(INT fAdjust)
  741. {
  742. REGISTER t;
  743. RECT rect;
  744. BOOL bDiffLevel = FALSE;
  745. RECT rectGame, rectHelp;
  746. // an extra check
  747. if (!hwndMain)
  748. return;
  749. dypAdjust = dypCaption;
  750. if (FMenuOn())
  751. {
  752. // dypMenu is initialized to GetSystemMetrics(SM_CYMENU) + 1,
  753. // which is the height of one menu line
  754. dypAdjust += dypMenu;
  755. // If the menu extends on two lines (because of the large-size
  756. // font the user has chosen for the menu), increase the size
  757. // of the window.
  758. // The two menus : "Game" and "Help" are on the same line, if
  759. // their enclosing rectangles top match. In that case, we don't
  760. // need to extend the window size.
  761. // If the tops do not match, that means they are on two lines.
  762. // In that case, extend the size of the window by size of
  763. // one menu line.
  764. if (hMenu && GetMenuItemRect(hwndMain, hMenu, 0, &rectGame) &&
  765. GetMenuItemRect(hwndMain, hMenu, 1, &rectHelp))
  766. {
  767. if (rectGame.top != rectHelp.top)
  768. {
  769. dypAdjust += dypMenu;
  770. bDiffLevel = TRUE;
  771. }
  772. }
  773. }
  774. dxWindow = dxBlk * xBoxMac + dxGridOff + dxRightSpace;
  775. dyWindow = dyBlk * yBoxMac + dyGridOff + dyBottomSpace;
  776. if ((t = Preferences.xWindow+dxWindow - OurGetSystemMetrics(SM_CXSCREEN)) > 0)
  777. {
  778. fAdjust |= fResize;
  779. Preferences.xWindow -= t;
  780. }
  781. if ((t = Preferences.yWindow+dyWindow - OurGetSystemMetrics(SM_CYSCREEN)) > 0)
  782. {
  783. fAdjust |= fResize;
  784. Preferences.yWindow -= t;
  785. }
  786. if (!bInitMinimized)
  787. {
  788. if (fAdjust & fResize)
  789. {
  790. MoveWindow(hwndMain, Preferences.xWindow, Preferences.yWindow,
  791. dxWindow+dxpBorder, dyWindow + dypAdjust, fTrue);
  792. }
  793. // after the window is adjusted, the "Game" and "Help" may move to the
  794. // same line creating extra space at the bottom. so check again!
  795. if (bDiffLevel && hMenu && GetMenuItemRect(hwndMain, hMenu, 0, &rectGame) &&
  796. GetMenuItemRect(hwndMain, hMenu, 1, &rectHelp))
  797. {
  798. if (rectGame.top == rectHelp.top)
  799. {
  800. dypAdjust -= dypMenu;
  801. MoveWindow(hwndMain, Preferences.xWindow, Preferences.yWindow,
  802. dxWindow+dxpBorder, dyWindow + dypAdjust, fTrue);
  803. }
  804. }
  805. if (fAdjust & fDisplay)
  806. {
  807. SetRect(&rect, 0, 0, dxWindow, dyWindow);
  808. InvalidateRect(hwndMain, &rect, fTrue);
  809. }
  810. }
  811. }