目前,在WM上进行手机来电铃声捕获的方法有两种,一种是TAPI,一种就是使用ril库,TAPI实施性不好,在来电铃声响一下才捕获到来电,用ril库可以在来电铃声响起来之前捕获到铃声,经过本人测试使用ril库时
在回调函数中
RIL_NOTIFY_CALLERID
RIL_NOTIFY_RING
这两个消息中可以在铃声响起之前获得消息, 甚至可以修改注册表达到修改来电铃声的目的,
下面附上部分代码:
LRESULT lresult;
result = RIL_Initialize(1, ResultCallback, NotifyCallback,
dwNotificationClasses, g_dwParam, &g_hRil);
void CALLBACK NotifyCallback(DWORD dwCode, const void *lpData,
DWORD cbData, DWORD dwParam)
{
TCHAR szString[256];
wsprintf(szString, L"notify: dwCode=0x%0X lpData=%p, cbData=%d",dwCode, lpData, cbData);
SendMessage(g_hwndEdit, LB_ADDSTRING, 0, (LPARAM) szString);
switch(dwCode)
{
case RIL_NOTIFY_RING: //receive an inbound voice call
{
static int i = 0;
LPRILRINGINFO ringInfo = (LPRILRINGINFO) lpData;
if(! bPlay)
{
WriteReg();
bPlay = TRUE;
}
break;
}
case RIL_NOTIFY_DISCONNECT:
{
WavePlay.Stop();
bPlay = FALSE;
break;
}
case RIL_NOTIFY_CONNECT: // To make an outbound voice call
{
LPRILCONNECTINFO connectInfo = (LPRILCONNECTINFO)lpData;
//RIL_GetCallList( g_hRil );
break;
}
case RIL_NOTIFY_CALLERID: //receive an inbound voice call
{
RILREMOTEPARTYINFO *rpi = (RILREMOTEPARTYINFO *)lpData;
NKDbgPrintfW(TEXT("Number: %s/n"), rpi->raAddress.wszAddress );//来电号码
if(! bPlay)
{
WriteReg();
bPlay = TRUE;
}
//m_Str_DisplayDialNum=m_Str_DisplayDialNum+_T(rpi->raAddress.wszAddress);
break;
}
default:
break;
}
void WriteReg(void)
{
LRESULT lr;
HRESULT hr = E_FAIL;
HKEY hKey = NULL;
DWORD dwDisposition;
TCHAR wszValue[10] = L"apw3r";
TCHAR wszDerectary[40] = L"//My Documents//kkk.3gp";
//TCHAR wszDerectary[40] = L"//Windows//Rings//Ring-Saffron.wma";
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"Sound", 0, REG_SZ, (LPBYTE) wszDerectary, (lstrlen(wszDerectary) + 1) * sizeof(TCHAR));
if (lr != ERROR_SUCCESS)
RegCloseKey(hKey);
lr = RegSetValueEx(hKey, L"SavedSound", 0, REG_SZ, (LPBYTE) wszDerectary, (lstrlen(wszDerectary) + 1) * sizeof(TCHAR));
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;
}