请问如何获取电话状态,如来电 ,通话中,有未接来电,正常等
有什么事件来捕获吗还是通过注册表能检视到如HKEY_LOCAL_MACHINE\System\State\Phone\status但不知道获取的数值怎么用
谢谢
------解决方案--------------------
监视注册表的方法
#include <regext.h>
#include "snapi.h"
const TCHAR c_szPhoneRegistryRootkey[] = TEXT("System\\State");
const TCHAR c_szPhoneRegistrySubkey[] = TEXT("Phone");
const TCHAR c_szPhoneSignalStrength[] = TEXT("Signal Strength");
const TCHAR c_szPhoneIncomingCallerNumber[] = TEXT("Incoming Caller Number");
const TCHAR c_szPhoneStatus[] = TEXT("Status");
#define MAX_NOTIF 3
enum NotifType
{
SignalStrength = 0,
IncomingCallerNumber,
PhoneRoaming
};
HREGNOTIFY g_hRegNotify[ MAX_NOTIF ] ;
// The call-back function for Registry Notifications.
void RegistryNotifyCallbackFunc(HREGNOTIFY hNotify, DWORD dwUserData, const PBYTE pData, const UINT cbData)
{
TCHAR szOutput[MAX_PATH];
// Identify the Notification received, based upon the User Data passed in, while registering for the notification.
switch( dwUserData )
{
case SignalStrength:
StringCchPrintf(szOutput, MAX_PATH, _T("The Signal Strength is %d"), (DWORD) *pData);
break;
case IncomingCallerNumber:
StringCchPrintf(szOutput, MAX_PATH, _T("The Incoming Caller Number is %s"), (TCHAR*)pData);
break;
case PhoneRoaming:
{
DWORD dw = 0;
// Copy the data sent to us into a local buffer.
memcpy(&dw, pData, cbData);
// Find out if the roaming status has been set by logically ANDing the data with the value 512 (the bitmask for roaming).
StringCchPrintf(szOutput, MAX_PATH, _T("The Roam Status of the Phone is %s"), ( dw & SN_PHONEROAMING_BITMASK ) == SN_PHONEROAMING_BITMASK ? _T("TRUE") : _T("FALSE") );
}
break;
default :
break;
}
OutputDebugString( szOutput );
return;
}
void RegisterForPhoneNotifications()
{
HKEY hKey;
// Let us open the registry to get a handle to the Phone Registry key.
if (S_OK == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szPhoneRegistryRootkey, 0, KEY_QUERY_VALUE, &hKey))
{
// Since we are registering for multiple notifications, let's pass some unique User Data for each notification ( 5th param ),
// which will help us identify the notification in the Call Back.
// Let us register for Signal strength notifications.
HRESULT hr = RegistryNotifyCallback(hKey,
c_szPhoneRegistrySubkey,
c_szPhoneSignalStrength,
RegistryNotifyCallbackFunc,
SignalStrength,
NULL,
&g_hRegNotify[ SignalStrength ] );
// Let us register for Incoming Caller Number notifications.
hr = RegistryNotifyCallback(hKey,
c_szPhoneRegistrySubkey,
c_szPhoneIncomingCallerNumber,
RegistryNotifyCallbackFunc,
IncomingCallerNumber,
NULL,
&g_hRegNotify [ IncomingCallerNumber ] );
// Let us register for Roaming status change notifications.
hr = RegistryNotifyCallback(hKey,
c_szPhoneRegistrySubkey,