Windows Mobile中如何更改来电铃声

来电铃声的设置在注册表中的HKEY_CURRENT_USER//ControlPanel//Sounds//RingTone0//Script下的值,就是所要播放的铃声文件。查看Windows Mobile下的注册表,用VS2005中Visual Studio Remote Tools->Remote Registry Editor工具就可以,不须其他的软件。
我们可以在电话来了后根据号码播放不同的铃声,然后在通话结束再将铃声恢复。下面是通过MAPI来实现
1.判断来电号码
VOID CALLBACK LineCallback(DWORD hDevice, DWORD dwMsg, DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
 switch(dwMsg)
    {
    case LINE_CALLINFO://1L呼叫信息
  {
   switch(dwParam1)
   {
   case LINECALLINFOSTATE_CALLERID://0x00008000
    {
     LINECALLINFO *lpCallInfo;
     lpCallInfo = (LINECALLINFO *)malloc(sizeof(LINECALLINFO)+1000);
     memset(lpCallInfo, 0, sizeof(LINECALLINFO)+1000);
     lpCallInfo->dwTotalSize = sizeof(LINECALLINFO)+1000;
     while (1)
     {
      lineGetCallInfo( (HCALL)hDevice, lpCallInfo);
      if (lpCallInfo->dwTotalSize < lpCallInfo->dwNeededSize)
       lpCallInfo = (LINECALLINFO *)realloc(lpCallInfo,lpCallInfo->dwNeededSize);
      else
       break;
     }
     
     lstrcpy(szPhoneNumber,(LPTSTR)((LPSTR)((DWORD)lpCallInfo+(DWORD)lpCallInfo->dwCallerIDOffset)));
     free(lpCallInfo);
     // szPhoneNumber  ---- 呼入的电话号码
     //char strPhoneNumber[30 + 1] = {0};
   //在这里根据号码来设置铃声
   
                 
}
  break;
 case LINE_LINEDEVSTATE:
  break;
 case LINE_APPNEWCALL:  //有呼叫进来23L
  break;
 case LINE_REPLY:
  break;
 case LINE_CALLSTATE:  //呼叫状态2
  {
  case LINECALLSTATE_DISCONNECTED://挂机
   {
         RedoReg();
   }
   break;
  }
  break;
 }
}
DWORD InitializeTAPI(void)
{
 ReadReg();//读系统中默认的铃声设置
     //在启动中加入初始化
 if ( lineInitialize( &LineApp, g_hInst, (LINECALLBACK)LineCallback, g_szAppWndClass, &LineHandleCount) == 0)
 {
  LineHandles = new HLINE[LineHandleCount];
  for(DWORD i = 0; i < LineHandleCount; i++)
  {
   int rc;
   DWORD ver;
   LINEEXTENSIONID extensionID;
   
   if ( lineNegotiateAPIVersion( LineApp, i, 0x00010003, 0x00020000, &ver, &extensionID) == 0)
   {
    rc = lineOpen( LineApp,
     i,
     &LineHandles[i],
     ver,
     0,
     (DWORD)0,
     LINECALLPRIVILEGE_MONITOR|LINECALLPRIVILEGE_OWNER,
     LINEMEDIAMODE_INTERACTIVEVOICE,
     NULL);
            }
        }
 }
 
 return 0;
}
2,读取并保存系统铃声
void ReadReg(void)
{
 HKEY hKey = NULL;
    HKEY hSubKey = NULL;
 LRESULT SS;
 SS = RegOpenKeyEx(HKEY_CURRENT_USER ,L"//ControlPanel//Sounds//RingTone0", 0,0,&hKey);
 if(ERROR_SUCCESS != SS)//打开注册表失败
  RegCloseKey (hKey);


 DWORD    lpType = 1; 
 DWORD   lpcbData = 80;
 SS = RegQueryValueEx(hKey ,L"Script", (LPDWORD)NULL,NULL,(BYTE*)lpData,&lpcbData);
 DWORD Result = GetLastError();
 if(ERROR_SUCCESS != SS)//读键值失败
  RegCloseKey (hKey);
}
3,更改铃声设置
void WriteReg(void)
{
 LRESULT lr;
 HRESULT hr = E_FAIL;
 HKEY hKey = NULL;
 DWORD dwDisposition;
 TCHAR wszValue[60] = L"a";
 
 lr = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("//ControlPanel//Sounds//RingTone0"),
  0, NULL, 0, 0, NULL,
  &hKey, &dwDisposition);
 if (lr != ERROR_SUCCESS)
  RegCloseKey(hKey);
 
 lr = RegSetValueEx(hKey, L"Script", 0, REG_SZ, (LPBYTE) wszValue, (lstrlen(wszValue) + 1) * sizeof(TCHAR));
 if (lr != ERROR_SUCCESS)
  RegCloseKey(hKey);
 
 RegCloseKey(hKey);
 hKey = NULL;
}

4.通话结束,释放资源并恢复系统铃声
void ReleaseLine(void)
{
 RedoReg();

 for ( DWORD i=0; i<LineHandleCount; i++ )
 {
  lineClose( LineHandles[ i ] );
 }
void ReadReg(void)
{
 HKEY hKey = NULL;
    HKEY hSubKey = NULL;
 LRESULT SS;
 SS = RegOpenKeyEx(HKEY_CURRENT_USER ,L"//ControlPanel//Sounds//RingTone0", 0,0,&hKey);
 if(ERROR_SUCCESS != SS)//打开注册表失败
  RegCloseKey (hKey);


 DWORD    lpType = 1; 
 DWORD   lpcbData = 80;
 SS = RegQueryValueEx(hKey ,L"Script", (LPDWORD)NULL,NULL,(BYTE*)lpData,&lpcbData);
 DWORD Result = GetLastError();
 if(ERROR_SUCCESS != SS)//读键值失败
  RegCloseKey (hKey);
}
 delete[] LineHandles;
 lineShutdown( LineApp );

}

注意包含头文件的顺序,否则会出现很多编译错误;在EVC上表现的比较明显

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值