在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),