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.

127 lines
2.9 KiB

  1. /****************/
  2. /* file: pref.c */
  3. /****************/
  4. #define _WINDOWS
  5. #include <windows.h>
  6. #include <port1632.h>
  7. #include "snake.h"
  8. #include "res.h"
  9. #include "rtns.h"
  10. #include "grafix.h"
  11. #include "pref.h"
  12. BOOL fUpdateIni = fFalse;
  13. LPSTR lpIniFile = "entpack.ini";
  14. extern CHAR szClass[];
  15. #define lpAppName szClass
  16. PREF Preferences;
  17. #define iszPrefxWindow 0
  18. #define iszPrefyWindow 1
  19. #define iszPrefSound 2
  20. #define iszPrefMenu 3
  21. #define iszPrefMouse 4
  22. #define iszPrefSkill 5
  23. #define iszPrefLevel 6
  24. #define iszPrefHiScore 7
  25. #define iszPrefHiLevel 8
  26. #define iszPrefHiID 9
  27. #define iszPrefColor 10
  28. #define iszPrefMax 11
  29. CHAR * rgszPref[iszPrefMax] =
  30. {
  31. "Xpos" ,
  32. "Ypos" ,
  33. "Sound" ,
  34. "Menu" ,
  35. "Mouse" ,
  36. "Skill" ,
  37. "Level" ,
  38. "HiScore" ,
  39. "HiLevel" ,
  40. "HiID" ,
  41. "Color"
  42. };
  43. extern INT dypCaption;
  44. extern INT dypMenu;
  45. /****** PREFERENCES ******/
  46. INT ReadInt(INT iszPref, INT valDefault, INT valMin, INT valMax)
  47. {
  48. return max(valMin, min(valMax,
  49. (INT) GetPrivateProfileInt(lpAppName, rgszPref[iszPref], valDefault, lpIniFile) ) );
  50. }
  51. #define ReadBool(iszPref, valDefault) ReadInt(iszPref, valDefault, 0, 1)
  52. VOID ReadPreferences(VOID)
  53. {
  54. INT dyp;
  55. Preferences.xWindow = ReadInt(iszPrefxWindow, 160, 0, 1024);
  56. dyp = dypCaption + dypMenu +
  57. max(0,(GetSystemMetrics(SM_CYSCREEN)-(dypGridOff+dypGrid+dypCaption+dypMenu))>>1);
  58. Preferences.yWindow = ReadInt(iszPrefyWindow, dyp, dyp, 1024);
  59. Preferences.fSound = ReadBool(iszPrefSound, fTrue);
  60. Preferences.fMenu = ReadInt(iszPrefMenu, fmenuAlwaysOn, fmenuAlwaysOn, fmenuOn);
  61. Preferences.fMouse = ReadBool(iszPrefMouse, fFalse);
  62. Preferences.skill = ReadInt(iszPrefSkill, skillInter, skillBegin, skillExpert);
  63. Preferences.level = ReadInt(iszPrefLevel, 0, 0, 99);
  64. Preferences.HiLevel = ReadInt(iszPrefHiLevel, 0, 0, 9999);
  65. fUpdateIni = (Preferences.HiScore = ReadInt(iszPrefHiScore, 0, 0, 9999)) == 0;
  66. {
  67. HDC hDC = GetDC(GetDesktopWindow());
  68. Preferences.fColor = ReadBool(iszPrefColor, (GetDeviceCaps(hDC, NUMCOLORS) != 2));
  69. ReleaseDC(GetDesktopWindow(),hDC);
  70. }
  71. }
  72. VOID WriteInt(INT iszPref, INT val)
  73. {
  74. CHAR szVal[15];
  75. wsprintf(szVal, "%d", val);
  76. #ifdef DEBUG2
  77. {
  78. CHAR sz[80];
  79. wsprintf(sz,"\r\n i=%d v=%d x=",iszPref, val);
  80. OutputDebugString(sz);
  81. OutputDebugString(szVal);
  82. OutputDebugString("\r\n rgszPref=");
  83. OutputDebugString(rgszPref[iszPref]);
  84. }
  85. #endif
  86. WritePrivateProfileString(lpAppName, rgszPref[iszPref], szVal, lpIniFile);
  87. }
  88. VOID WritePreferences(VOID)
  89. {
  90. WriteInt(iszPrefSound, Preferences.fSound);
  91. #ifdef OH_WELL
  92. WriteInt(iszPrefMouse, Preferences.fMouse);
  93. #endif
  94. WriteInt(iszPrefSkill, Preferences.skill);
  95. WriteInt(iszPrefLevel, Preferences.level);
  96. WriteInt(iszPrefHiScore, Preferences.HiScore);
  97. WriteInt(iszPrefHiLevel, Preferences.HiLevel);
  98. WriteInt(iszPrefxWindow, Preferences.xWindow);
  99. WriteInt(iszPrefyWindow, Preferences.yWindow);
  100. WriteInt(iszPrefColor, Preferences.fColor);
  101. }