waveOutSetVolume 振动Pocket PC和Smart Phone不一样 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); } BOOL NLedDriverSetDevice( INT nInfoId, PVOID pInput ); 在PPC上,震动是以LED灯的形式控制的,你可以使用 BOOL WINAPI NLedGetDeviceInfo( UINT nInfoId, void* pOutput ); [DllImport("coredll.dll")] public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume); 获得当前音量 [DllImport("coredll.dll")] public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume); 设置音量值 设置震动、静音 使用aygshell.dll中的SndSetSound函数 [DllImport("aygshell.dll", SetLastError = true)] private static extern uint SndSetSound(SoundEvent seSoundEvent, ref SNDFILEINFO pSoundFileInfo, bool fSuppressUI);