//设置铃声大小 iVol: 0-5
void SetRingVol(int iVol)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\SoundCategories\\Ring\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
DWORD dwValue = iVol;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
if(res != ERROR_SUCCESS)
return;
RegSetValueEx(hKey, _T("InitVol"), 0, dwType, (BYTE*)&dwValue, dwcbData);
RegCloseKey(hKey);
}
//获取铃声大小 iVol: 0-5
void GetRingVol(int *iVol)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\SoundCategories\\Ring\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
DWORD dwValue;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegQueryValueEx(hKey, _T("InitVol"), 0, &dwType, (BYTE *)&dwValue, &dwcbData);
if(res == ERROR_SUCCESS)
*iVol = (int)dwValue;
RegCloseKey(hKey);
}
//获取显示状态 0:打开 1:振动 2:关闭
void GetMode(int *iMode)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
DWORD dwValue;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegQueryValueEx(hKey, _T("Mode"), 0, &dwType, (BYTE *)&dwValue, &dwcbData);
if(res == ERROR_SUCCESS)
*iMode = (int)dwValue;
RegCloseKey(hKey);
}
//设置显示状态 0:打开 1:振动 2: 关闭
void SetMode(int iMod)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
DWORD dwValue = iMod;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegSetValueEx(hKey, _T("Mode"), 0, dwType, (BYTE *)&dwValue, dwcbData);
RegCloseKey(hKey);
}
//设置铃声模式 0:铃声 1:振动 2:无
void SetSound(int iStatus)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Sounds\\RingTone0\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
TCHAR szData[50];
DWORD dwType = REG_SZ;
DWORD dwcbData = sizeof(szData);
if(iStatus == 0)
{//响铃方式,则铃声为SavedSound下的铃声
RegQueryValueEx(hKey, _T("SavedSound"), 0, &dwType, (BYTE *)szData, &dwcbData);
}
else if(iStatus == 1)
{//振动方式
_tcscpy(szData, _T("*vibrate*"));
}
else if(iStatus == 2)
{//不响铃也不振动
_tcscpy(szData, _T("*none*"));
}
RegSetValueEx(hKey, _T("Sound"), 0, dwType, (BYTE *)szData, dwcbData);
RegCloseKey(hKey);
SetMode(iStatus);
}
//获取铃声模式 0:铃声 1:振动 2:无
int GetSound()
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Sounds\\RingTone0\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return FALSE;
TCHAR szData[50];
DWORD dwType = REG_SZ;
DWORD dwcbData = sizeof(szData);
RegQueryValueEx(hKey, _T("Sound"), 0, &dwType, (BYTE *)szData, &dwcbData);
if( _tcscmp(szData, _T("*vibrate*")) == 0) //振动
res = 1;
else if(_tcscmp(szData, _T("*none*")) == 0) //无
res = 2;
else
res = 0; //铃声
RegCloseKey(hKey);
return res;
}
//获取已保存的铃声音量 iSRVol : 0 ~ 5
int GetSavedRingVol()
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return FALSE;
DWORD dwValue = 0;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegQueryValueEx(hKey, _T("SavedRingerVolume"), 0, &dwType, (BYTE *)&dwValue, &dwcbData);
if(res == ERROR_SUCCESS)
{//转换为0~5
dwValue /= 0x33333333;
}
RegCloseKey(hKey);
return dwValue;
}
//保存Mobile系统主音量
void SaveSysVol(DWORD dwValue)
{
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
if(!RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey))
{
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
RegSetValueEx(hKey, _T("SavedVolume"), 0, dwType, (BYTE *)&dwValue, dwcbData);
RegCloseKey(hKey);
}
}
//这是一个示例,设置系统主音量
void SetVolume(DWORD dwVol)
{
int iSound = GetSound(); //获取先前铃声模式
if(iSound == 0) //先前为响钤方式,直接调音量
{
waveOutSetVolume(NULL, dwVol);
SaveSysVol(dwVol); //需要保存系统音量
}
else //先前为其它状态
{
waveOutSetVolume(NULL, dwVol);
SaveSysVol(dwVol); //设置完音量后保存
SetSound(0); //设置为响铃方式
SetMode(0); //显示为"打开"状态
int iRingVol = GetSavedRingVol(); //获取先前铃声音量
SetRingVol(iRingVol); //恢复铃声音量
}
void SetRingVol(int iVol)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\SoundCategories\\Ring\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
DWORD dwValue = iVol;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
if(res != ERROR_SUCCESS)
return;
RegSetValueEx(hKey, _T("InitVol"), 0, dwType, (BYTE*)&dwValue, dwcbData);
RegCloseKey(hKey);
}
//获取铃声大小 iVol: 0-5
void GetRingVol(int *iVol)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\SoundCategories\\Ring\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
DWORD dwValue;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegQueryValueEx(hKey, _T("InitVol"), 0, &dwType, (BYTE *)&dwValue, &dwcbData);
if(res == ERROR_SUCCESS)
*iVol = (int)dwValue;
RegCloseKey(hKey);
}
//获取显示状态 0:打开 1:振动 2:关闭
void GetMode(int *iMode)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
DWORD dwValue;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegQueryValueEx(hKey, _T("Mode"), 0, &dwType, (BYTE *)&dwValue, &dwcbData);
if(res == ERROR_SUCCESS)
*iMode = (int)dwValue;
RegCloseKey(hKey);
}
//设置显示状态 0:打开 1:振动 2: 关闭
void SetMode(int iMod)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
DWORD dwValue = iMod;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegSetValueEx(hKey, _T("Mode"), 0, dwType, (BYTE *)&dwValue, dwcbData);
RegCloseKey(hKey);
}
//设置铃声模式 0:铃声 1:振动 2:无
void SetSound(int iStatus)
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Sounds\\RingTone0\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return;
TCHAR szData[50];
DWORD dwType = REG_SZ;
DWORD dwcbData = sizeof(szData);
if(iStatus == 0)
{//响铃方式,则铃声为SavedSound下的铃声
RegQueryValueEx(hKey, _T("SavedSound"), 0, &dwType, (BYTE *)szData, &dwcbData);
}
else if(iStatus == 1)
{//振动方式
_tcscpy(szData, _T("*vibrate*"));
}
else if(iStatus == 2)
{//不响铃也不振动
_tcscpy(szData, _T("*none*"));
}
RegSetValueEx(hKey, _T("Sound"), 0, dwType, (BYTE *)szData, dwcbData);
RegCloseKey(hKey);
SetMode(iStatus);
}
//获取铃声模式 0:铃声 1:振动 2:无
int GetSound()
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Sounds\\RingTone0\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return FALSE;
TCHAR szData[50];
DWORD dwType = REG_SZ;
DWORD dwcbData = sizeof(szData);
RegQueryValueEx(hKey, _T("Sound"), 0, &dwType, (BYTE *)szData, &dwcbData);
if( _tcscmp(szData, _T("*vibrate*")) == 0) //振动
res = 1;
else if(_tcscmp(szData, _T("*none*")) == 0) //无
res = 2;
else
res = 0; //铃声
RegCloseKey(hKey);
return res;
}
//获取已保存的铃声音量 iSRVol : 0 ~ 5
int GetSavedRingVol()
{
int res;
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
res = RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
if(res != ERROR_SUCCESS)
return FALSE;
DWORD dwValue = 0;
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
res = RegQueryValueEx(hKey, _T("SavedRingerVolume"), 0, &dwType, (BYTE *)&dwValue, &dwcbData);
if(res == ERROR_SUCCESS)
{//转换为0~5
dwValue /= 0x33333333;
}
RegCloseKey(hKey);
return dwValue;
}
//保存Mobile系统主音量
void SaveSysVol(DWORD dwValue)
{
HKEY hKey;
TCHAR *szSubKey = _T("ControlPanel\\Notifications\\ShellOverrides\\");
if(!RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey))
{
DWORD dwType = REG_DWORD;
DWORD dwcbData = sizeof(DWORD);
RegSetValueEx(hKey, _T("SavedVolume"), 0, dwType, (BYTE *)&dwValue, dwcbData);
RegCloseKey(hKey);
}
}
//这是一个示例,设置系统主音量
void SetVolume(DWORD dwVol)
{
int iSound = GetSound(); //获取先前铃声模式
if(iSound == 0) //先前为响钤方式,直接调音量
{
waveOutSetVolume(NULL, dwVol);
SaveSysVol(dwVol); //需要保存系统音量
}
else //先前为其它状态
{
waveOutSetVolume(NULL, dwVol);
SaveSysVol(dwVol); //设置完音量后保存
SetSound(0); //设置为响铃方式
SetMode(0); //显示为"打开"状态
int iRingVol = GetSavedRingVol(); //获取先前铃声音量
SetRingVol(iRingVol); //恢复铃声音量
}
}
Mobile5.0与Mobile6.0下调整响铃方式的区别之一
Mobile5.0时调整为振动或无方式时,系统主量必须调为0,而Mobile6.0则无此限制