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.

134 lines
2.9 KiB

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