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.

148 lines
2.7 KiB

  1. /**********/
  2. /* util.c */
  3. /**********/
  4. #define _WINDOWS
  5. #include <windows.h>
  6. #include <port1632.h>
  7. #include "main.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(INT idErr)
  35. {
  36. CHAR szMsg[cchMsgMax];
  37. CHAR szMsgTitle[cchMsgMax];
  38. if (idErr < ID_ERR_MAX)
  39. LoadString(hInst, (WORD)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(INT id, CHAR * sz)
  50. {
  51. if (LoadString(hInst, (WORD)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) < 351;
  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(INT idm, BOOL fCheck)
  68. {
  69. /*JAP fix 7/25/91)*/
  70. CheckMenuItem(hMenu, (WORD)idm, (DWORD) (fCheck ? MF_CHECKED : MF_UNCHECKED));
  71. }
  72. /****** S E T M E N U B A R ******/
  73. VOID SetMenuBar(INT fActive)
  74. {
  75. Preferences.fMenu = fActive;
  76. FixMenus();
  77. SetMenu(hwndMain, FMenuOn() ? hMenu : NULL);
  78. AdjustWindow(fResize);
  79. }
  80. /****** D O A B O U T ******/
  81. VOID DoAbout(VOID)
  82. {
  83. CHAR szVersion[cchMsgMax];
  84. CHAR szCredit[cchMsgMax];
  85. LoadSz(ID_MSG_VERSION, szVersion);
  86. LoadSz(ID_MSG_CREDIT, szCredit);
  87. AboutWEP(hwndMain, LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_MAIN)),
  88. szVersion, szCredit);
  89. }
  90. /****** D O H E L P ******/
  91. VOID DoHelp(UINT wCommand, ULONG_PTR lParam)
  92. {
  93. CHAR szHelpFile[cchMaxPathname];
  94. CHAR * pch;
  95. pch = szHelpFile + GetModuleFileName(hInst, szHelpFile, cchMaxPathname);
  96. if ( ((pch-szHelpFile) > 4) && (*(pch-4) == '.') )
  97. pch -= 4;
  98. lstrcpy((LPSTR) pch, (LPSTR) ".HLP");
  99. WinHelp(hwndMain, szHelpFile, wCommand, lParam);
  100. }