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.

167 lines
2.9 KiB

  1. /**********/
  2. /* util.c */
  3. /**********/
  4. #define _WINDOWS
  5. #include <windows.h>
  6. #include <port1632.h>
  7. #include "snake.h"
  8. #include "res.h"
  9. #include "pref.h"
  10. #include "util.h"
  11. #include "string.h"
  12. #include "stdio.h"
  13. #include "stdlib.h"
  14. #include "dos.h"
  15. extern INT dypBorder;
  16. extern INT dxpBorder;
  17. extern INT dypCaption;
  18. extern INT dypMenu;
  19. extern CHAR szClass[cchNameMax];
  20. extern HANDLE hInst;
  21. extern HWND hwndMain;
  22. extern HMENU hMenu;
  23. extern BOOL fEGA;
  24. extern PREF Preferences;
  25. VOID APIENTRY AboutWEP(HWND hwnd, HICON hicon, LPSTR lpTitle, LPSTR lpCredit);
  26. /****** R N D ******/
  27. /* Return a random number between 0 and rndMax */
  28. INT Rnd(INT rndMax)
  29. {
  30. return (rand() % rndMax);
  31. }
  32. /****** R E P O R T E R R ******/
  33. /* Report and error and exit */
  34. VOID ReportErr(WORD idErr)
  35. {
  36. CHAR szMsg[cchMsgMax];
  37. CHAR szMsgTitle[cchMsgMax];
  38. if (idErr < ID_ERR_MAX)
  39. LoadString(hInst, idErr, szMsg, cchMsgMax);
  40. else
  41. {
  42. LoadString(hInst, ID_ERR_UNKNOWN, szMsgTitle, cchMsgMax);
  43. wsprintf(szMsg, szMsgTitle, idErr);
  44. }
  45. LoadString(hInst, ID_ERR_TITLE, szMsgTitle, cchMsgMax);
  46. MessageBox(NULL, szMsg, szMsgTitle, MB_OK | MB_ICONHAND);
  47. }
  48. /****** L O A D S Z ******/
  49. VOID LoadSz(WORD id, CHAR * sz)
  50. {
  51. if (LoadString(hInst, id, (LPSTR) sz, cchMsgMax) == 0)
  52. ReportErr(1001);
  53. }
  54. /****** I N I T C O N S T ******/
  55. VOID InitConst(VOID)
  56. {
  57. srand(LOWORD(GetCurrentTime()));
  58. LoadSz(ID_GAMENAME, szClass);
  59. fEGA = GetSystemMetrics(SM_CYSCREEN) == 350;
  60. dypCaption = GetSystemMetrics(SM_CYCAPTION) + 1;
  61. dypMenu = GetSystemMetrics(SM_CYMENU) + 1;
  62. dypBorder = GetSystemMetrics(SM_CYBORDER) + 1;
  63. dxpBorder = GetSystemMetrics(SM_CXBORDER) + 1;
  64. }
  65. /* * * * * * M E N U S * * * * * */
  66. /****** C H E C K E M ******/
  67. VOID CheckEm(WORD idm, BOOL fCheck)
  68. {
  69. CheckMenuItem(hMenu, idm, fCheck ? MF_CHECKED : MF_UNCHECKED);
  70. }
  71. /****** S E T M E N U B A R ******/
  72. VOID SetMenuBar(INT fActive)
  73. {
  74. Preferences.fMenu = fActive;
  75. FixMenus();
  76. SetMenu(hwndMain, FMenuOn() ? hMenu : NULL);
  77. AdjustWindow(fResize);
  78. }
  79. /****** D O A B O U T ******/
  80. VOID DoAbout(VOID)
  81. {
  82. CHAR szVersion[cchMsgMax];
  83. CHAR szCredit[cchMsgMax];
  84. LoadSz(ID_MSG_VERSION, szVersion);
  85. LoadSz(ID_MSG_CREDIT, szCredit);
  86. AboutWEP(hwndMain, LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_MAIN)),
  87. szVersion, szCredit);
  88. }
  89. /****** D O H E L P ******/
  90. VOID DoHelp(UINT wCommand, ULONG_PTR lParam)
  91. {
  92. CHAR szHelpFile[cchMaxPathname];
  93. CHAR * pch;
  94. pch = szHelpFile + GetModuleFileName(hInst, szHelpFile, cchMaxPathname);
  95. if ( ((pch-szHelpFile) > 4) && (*(pch-4) == '.') )
  96. pch -= 4;
  97. lstrcpy((LPSTR) pch, (LPSTR) ".HLP");
  98. WinHelp(hwndMain, szHelpFile, wCommand, lParam);
  99. }
  100. /****** G E T D L G I N T ******/
  101. INT GetDlgInt(HWND hDlg, INT dlgID, INT numLo, INT numHi)
  102. {
  103. INT num;
  104. BOOL fFlag;
  105. num = GetDlgItemInt(hDlg, dlgID, &fFlag, fFalse);
  106. if (num < numLo)
  107. num = numLo;
  108. else if (num > numHi)
  109. num = numHi;
  110. return num;
  111. }