在Main中GetMessage,或用MFC直接注册这个消息(手动加):
h文件中声明消息处理涵数:
afx_msg LRESULT OnProcess(WPARAM wParam, LPARAM lParam);
在cpp文件的消息映射中加上:
ON_MESSAGE(WM_DBNOTIFICATION,OnProcess)
关加上实现代码:前提是EDB数据库必须打开,可监听联系人,来电数据库的变化.
LRESULT CMainFrame::OnProcess(WPARAM wParam, LPARAM lParam)
{
CENOTIFICATION *pNotification = NULL;
pNotification = (CENOTIFICATION*)lParam;
if( pNotification->uType != DB_CEOID_CREATED)
return S_FALSE;
if(INVALID_HANDLE_VALUE == CeGetDatabaseSession(g_hDB))
return S_FALSE;
pNotification = (CENOTIFICATION*)lParam;
CEOID oid = pNotification->oid;
WORD wNumRecProps = 0;
LPBYTE lpRecProps = NULL;
PCEPROPVAL pCePropVal;
DWORD dwBufLen = 128;
CEOID ceoid = CeSeekDatabaseEx(g_hDB,CEDB_SEEK_CEOID,oid,1,NULL);
if(!ceoid)
{
DWORD dwErr = GetLastError();
return dwErr;
}
ceoid = CeReadRecordPropsEx(g_hDB, CEDB_ALLOWREALLOC, &wNumRecProps, NULL, &lpRecProps, &dwBufLen, NULL);
if(!ceoid)
{
DWORD dwErr = GetLastError();
return dwErr;
}
pCePropVal = (PCEPROPVAL)lpRecProps;
CeFreeNotification(&edbCalllog,pNotification);
//////////////////////////////////////////////////////////////////////
return S_OK;
}
相对于CEDB,则是CEDB_EXNOTIFICATION.这个消息不适用短信数据库(cemail.vol),