Wince 通过HotKey动态调节音量控制

参照以前driverdevelop上zhengshijie的transparent程序,加入windows CE下HotKey操作,组合一下完成这个小程序,以供娱乐。

 

加入HotKey操作

void CTransparentWnd::LoadHotkey() { UINT Modifiers = NULL; UINT KeyAdd = 3; UINT KeyMinus = 2; UINT KeySilent = 1; Modifiers=MOD_ALT; #if 0 RegisterHotKey(this->m_hWnd, 555, Modifiers, KeyAdd+VK_F1); RegisterHotKey(this->m_hWnd, 556, Modifiers, KeyMinus+VK_F1); RegisterHotKey(this->m_hWnd, 557, Modifiers, KeySilent+VK_F1); #else RegisterHotKey(this->m_hWnd, 555, Modifiers, VK_UP); RegisterHotKey(this->m_hWnd, 556, Modifiers, VK_DOWN); RegisterHotKey(this->m_hWnd, 557, Modifiers, VK_F2); #endif }

默认的是Alt+F2,F3,F4来控制,我稍微修改了一下,采用Alt+↑,Alt+↓来加减音量

 

加入音量操作

BOOL CTransparentWnd::SetVolumeReg(void) { HKEY hKey; LONG lResult; DWORD dwType; DWORD dwVal; // Calculate the volume that's being set int NewVolume = (int)(((int)MaxValue / 10) * vol); if (NewVolume > 0xfd00) { NewVolume = 0xffff; } // Set the same volume for both the left and the right channels uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16)); // Set the volume waveOutSetVolume(0, NewVolumeAllChannels); lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("ControlPanel//Volume"), 0, KEY_ALL_ACCESS, &hKey); if(ERROR_SUCCESS == lResult) { dwType = REG_DWORD; dwVal = NewVolumeAllChannels; lResult = RegSetValueEx(hKey, _T("Volume"), 0, dwType, (LPBYTE)&dwVal, sizeof(DWORD)); RegCloseKey(hKey); return TRUE; } else { return FALSE; } } BOOL CTransparentWnd::GetVolumeReg(void) { HKEY hKey; LONG lResult; DWORD dwType; DWORD dwVal; DWORD dwLen; lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("ControlPanel//Volume"), 0, KEY_ALL_ACCESS, &hKey); if(ERROR_SUCCESS == lResult) { dwType = REG_DWORD; dwLen = sizeof(DWORD); lResult = RegQueryValueEx(hKey, _T("Volume"), NULL, &dwType,(LPBYTE)&dwVal, &dwLen); if(ERROR_SUCCESS == lResult) { m_Volume = dwVal; RegCloseKey(hKey); //waveOutGetVolume(0, (unsigned long)m_Volume); DWORD CalcVol = (DWORD)(dwVal & 0x0000ffff); if (CalcVol > 0xfd00) CalcVol = 0xffff; // Get the volume on a scale of 1 to 10 (to fit the trackbar) vol = (int)(DWORD)(CalcVol / ((DWORD)MaxValue / 10)); return TRUE; } else { return FALSE; } } else { return FALSE; } }

通过读写注册表来实现获取当前音量,然后通过waveOutSetVolume()来设置音量。

 

其实也可以通过waveOutSetVolume(),waveOutGetVolume()来获取和设置系统音量,而不需要读写注册表这么复杂。

 

大概调试了一下,效果基本满意。只是在一直按住Alt+↑或Alt+↓时,音量进度条未能实时更新,音量也未实时更新。

 

后续还得进一步优化。

 

虚拟机上效果如下

Wince 通过HotKey动态调节音量控制_第1张图片

 

执行程序下载地址,支持分辨率为800x480,显示效果最佳

http://download.csdn.net/source/2584410

 

你可能感兴趣的:(虚拟机,windows,娱乐,user,Access,WinCE)