propsound.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // PropSound.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "cliconfig.h"
  5. #include "PropSound.h"
  6. #include "regkey.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPropSound property page
  14. IMPLEMENT_DYNCREATE(CPropSound, CPropertyPage)
  15. CPropSound::CPropSound() : CPropertyPage(CPropSound::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CPropSound)
  18. m_bHardwareSound = TRUE;
  19. m_bMusic = TRUE;
  20. m_nMusicGain = 10;
  21. m_nSoundFXGain = 5;
  22. m_nVoiceOverGain = 0;
  23. m_nSoundQuality = 1;
  24. //}}AFX_DATA_INIT
  25. }
  26. CPropSound::~CPropSound()
  27. {
  28. }
  29. void CPropSound::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CPropSound)
  33. DDX_Check(pDX, IDC_HARDWARESOUND, m_bHardwareSound);
  34. DDX_Check(pDX, IDC_MUSIC, m_bMusic);
  35. DDX_Text(pDX, IDC_MUSICGAIN, m_nMusicGain);
  36. DDX_Text(pDX, IDC_SOUNDFXGAIN, m_nSoundFXGain);
  37. DDX_Text(pDX, IDC_VOICEOVERGAIN, m_nVoiceOverGain);
  38. DDX_Slider(pDX, IDC_SOUNDQUALITY, m_nSoundQuality);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CPropSound, CPropertyPage)
  42. //{{AFX_MSG_MAP(CPropSound)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CPropSound message handlers
  47. BOOL CPropSound::OnInitDialog()
  48. {
  49. CPropertyPage::OnInitDialog();
  50. CSliderCtrl* pSlider = (CSliderCtrl*)GetDlgItem(IDC_SOUNDQUALITY);
  51. pSlider->SetRange(1, 3);
  52. pSlider->SetTicFreq(1);
  53. // get the stuff from the registry
  54. HKEY hKey;
  55. DWORD dwType;
  56. DWORD dwValue;
  57. DWORD cbValue;
  58. if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, KEY_READ, &hKey))
  59. {
  60. cbValue = sizeof(dwValue);
  61. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "SoundHardwareAcceleration", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  62. m_bHardwareSound = (dwValue==1) ? 1 : 0;
  63. cbValue = sizeof(dwValue);
  64. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "Music", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  65. m_bMusic = (dwValue==1) ? 1 : 0;
  66. cbValue = sizeof(dwValue);
  67. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "MusicGain", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  68. m_nMusicGain = dwValue;
  69. cbValue = sizeof(dwValue);
  70. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "SFXGain", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  71. m_nSoundFXGain = dwValue;
  72. cbValue = sizeof(dwValue);
  73. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "VoiceOverGain", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  74. m_nVoiceOverGain = dwValue;
  75. cbValue = sizeof(dwValue);
  76. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "SoundQuality", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  77. m_nSoundQuality = dwValue;
  78. RegCloseKey(hKey);
  79. }
  80. UpdateData(false);
  81. return TRUE; // return TRUE unless you set the focus to a control
  82. // EXCEPTION: OCX Property Pages should return FALSE
  83. }
  84. void CPropSound::OnOK()
  85. {
  86. UpdateData(true);
  87. HKEY hKey;
  88. DWORD dw;
  89. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw))
  90. {
  91. DWORD dwValueOne = 1;
  92. DWORD dwValueZero = 0;
  93. ::RegSetValueEx(hKey, "SoundHardwareAcceleration", NULL, REG_DWORD,
  94. (const unsigned char*)(m_bHardwareSound ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  95. ::RegSetValueEx(hKey, "Music", NULL, REG_DWORD,
  96. (const unsigned char*)(m_bMusic ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  97. ::RegSetValueEx(hKey, "MusicGain", NULL, REG_DWORD,
  98. (const unsigned char*)&m_nMusicGain, sizeof(DWORD));
  99. ::RegSetValueEx(hKey, "SFXGain", NULL, REG_DWORD,
  100. (const unsigned char*)&m_nSoundFXGain, sizeof(DWORD));
  101. ::RegSetValueEx(hKey, "VoiceOverGain", NULL, REG_DWORD,
  102. (const unsigned char*)&m_nVoiceOverGain, sizeof(DWORD));
  103. ::RegSetValueEx(hKey, "SoundQuality", NULL, REG_DWORD,
  104. (const unsigned char*)&m_nSoundQuality, sizeof(DWORD));
  105. ::RegCloseKey(hKey);
  106. }
  107. CPropertyPage::OnOK();
  108. }