|
void UpdateVolumeFromRegistry()
{
HINSTANCE hLibrary = ::LoadLibrary(_T("coredll.dll"));
if (NULL == hLibrary)
return;
typedef DWORD (*pAudio) ();
pAudio pProc = (pAudio)::GetProcAddress(hLibrary, _T("AudioUpdateFromRegistry"));
if (NULL == pProc)
{
::FreeLibrary(hLibrary);
return;
}
pProc();
::FreeLibrary(hLibrary);
}
void SetVolume(DWORD dwVolume)
{
//通过注册表设置音量
HKEY hk = NULL;
DWORD dwSize;
DWORD dwDisposition;
int iResult;
if((iResult = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("ControlPanel\\Volume"),
(DWORD) 0, TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
(LPSECURITY_ATTRIBUTES) NULL,
&hk,
&dwDisposition)) == ERROR_SUCCESS)
{
dwSize = sizeof(DWORD);
RegSetValueEx(hk, _T("Volume"), 0, REG_DWORD, (LPBYTE)&dwVolume, sizeof(DWORD));
waveOutSetVolume(0, dwVolume);
UpdateVolumeFromRegistry();
RegCloseKey(hk);
}
} |
|