⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addrejectedcall.cpp

📁 Windows Mobile 上的通话记录定制源代码
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
////////////////////////////////////////////////////////////////////////////
//
//  This is "Sample Code" and is distributable subject to the terms of the end 
//  user license agreement.
//
//  The example companies, organizations, products, domain names,
//  e-mail addresses, logos, people, places, and events depicted herein are
//  fictitious.  No association with any real company, organization, product,
//  domain name, email address, logo, person, places, or events is intended
//  or should be inferred.
//
/////////////////////////////////////////////////////////////////////////////

/****************************************************************************
 This is a sample showing how to add a rejected call entry to the Call Log
 database.

 See ReadMe.txt for more information about how to use this sample.
****************************************************************************/


// Use EDB databases
#define EDB


#include <windows.h>
#include <windbase.h>
#include <phcanvas.h>
#include <phlog.h>


// Define globals
const DWORD gc_dwMaxRecords = 300;


// Declare functions needed by WinMain
HRESULT AddRejectedCall(LPWSTR pwszName, LPWSTR pwszNumber);

// **************************************************************************
// Function Name: WinMain
// 
// Purpose: Add rejected call to the Call Log database for the phone.
//
BOOL WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPWSTR    lpCmdLine,
                    int       iCmdShow)
{
    return SUCCEEDED(AddRejectedCall(_T("John Evans"), _T("425-555-0100")));
}


// Declare functions needed by AddRejectedCall
HRESULT AddRejectedCallHelper(HANDLE hCallLog, WORD cPropIds, CEPROPVAL *prgPropVal);

// **************************************************************************
// Function Name: AddRejectedCall
// 
// Purpose: Update the call cost data for the last call record in the Call Log database.
//
// Arguments:
//     IN LPWSTR pwszName - Name of caller rejected.
//     IN LPWSTR pwszNumber - Number of caller rejected.
//
// Return Values:
//     HRESULT
//
// Remarks:
//     This function inserts a static set of property values for purposes of
//     the sample.  In an actual implementation, data from the network would
//     need to be sent so that the actual rejected call details are written.
//     Great care should be taken to ensure that the network data is valid.
//     In particular, LPGID_CIDNAME and LPGID_CIDNUMBER must be bounded.
//
HRESULT AddRejectedCall(LPWSTR pwszName, LPWSTR pwszNumber)
{
    HRESULT hr = E_FAIL;

    HANDLE hCallLog = INVALID_HANDLE_VALUE;

    CEPROPVAL rgpropval[5];
    FILETIME ftNow;
    SYSTEMTIME stNow;
    WORD cPropIds = 0;

    if (!pwszName)
    {
        hr = E_INVALIDARG;
        goto Exit;
    }

    // Get current time to use as start and end time for this rejected call.
    GetSystemTime(&stNow);
    SystemTimeToFileTime(&stNow, &ftNow);

    // Set propval for bit flags to set call as an OEM extended missed call.
    rgpropval[cPropIds].propid = LGPID_FLAGS;
    rgpropval[cPropIds].wFlags = 0;
    rgpropval[cPropIds++].val.lVal = LGIF_DIN |          // Incoming call
                                     LGIF_CNOTALK |      // Call missed
                                     LGIF_EEND |         // Call ended
                                     LGIF_VVOICE |       // Voice call (instead of data)
                                     LGIF_BLOCAL |       // Local call (instead of roaming)
                                     LGIF_L0 |           // Call on line 0
                                     LGIF_IAVAIL |       // Caller ID available
                                     LGIF_UHAVEENDTIME | // End time of call is known
                                     LGIF_OCUSTOMICO;    // Call should use an OEM supplied icon in the call log

    // Set propval for name of caller rejected
    rgpropval[cPropIds].propid = LGPID_CIDNAME;
    rgpropval[cPropIds].wFlags = 0;
    rgpropval[cPropIds++].val.lpwstr = (pwszName ? pwszName : L"");

    // Set propval for phone number of caller rejected
    rgpropval[cPropIds].propid = LGPID_CIDNUMBER;
    rgpropval[cPropIds].wFlags = 0;
    rgpropval[cPropIds++].val.lpwstr = (pwszNumber ? pwszNumber : L"");

    // Set propval for start time of caller rejected
    rgpropval[cPropIds].propid = LGPID_STARTTIME;
    rgpropval[cPropIds].wFlags = 0;
    rgpropval[cPropIds++].val.filetime = ftNow;

    // Set propval for end time of caller rejected
    rgpropval[cPropIds].propid = LGPID_ENDTIME;
    rgpropval[cPropIds].wFlags = 0;
    rgpropval[cPropIds++].val.filetime = ftNow;
    
    hr = PhoneOpenCallLog(&hCallLog);
    if (FAILED(hr))
    {
        DEBUGMSG(TRUE, (_T("PhoneOpenCallLog failed: (HRESULT)0x%lx.\r\n"), hr));
        goto Exit;
    }

    hr = AddRejectedCallHelper(hCallLog, cPropIds, rgpropval);

Exit:

    if (INVALID_HANDLE_VALUE != hCallLog)
    {
        PhoneCloseCallLog(hCallLog);
    }
    
    return hr;
}


// **************************************************************************
// Function Name: AddRejectedCallHelper
// 
// Purpose: Ensure the Call Log has less than a set number of records
//          then add the specified record.
//
// Arguments:
//     IN HANDLE hCallLog - Handle to the Call Log.
//     IN WORD cPropIds - Number of properties in the record to be added.
//     IN CEPROPVAL *prgPropVal - Pointer to array of property values for the record.
//
// Return Values:
//     HRESULT
//
HRESULT AddRejectedCallHelper(HANDLE hCallLog, WORD cPropIds, CEPROPVAL *prgPropVal)
{
    HRESULT hr = S_OK;

    CEOID oidRet;

    // Ensure number of records is less than gc_dwMaxRecords.
    // Records are sorted with the oldest records at the tail so delete from there.
    // We use gc_dwMaxRecords - 1 since we need to add one record.
    while ((oidRet = CeSeekDatabaseEx(hCallLog, CEDB_SEEK_BEGINNING,
                                      gc_dwMaxRecords - 1, 0, NULL)))
    {
        if (!CeDeleteRecord(hCallLog, oidRet))
        {
            DEBUGMSG(TRUE,
                     (_T("AddRejectedCallHelper: CeDeleteRecord failed: 0x%lx.\r\n"),
                      GetLastError()));
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto Exit;
        }
    }

    // Add record
    oidRet = CeWriteRecordProps(hCallLog, 0, cPropIds, prgPropVal);
    if (!oidRet)
    {
        DEBUGMSG(TRUE,
                 (_T("AddRejectedCallHelper: CeWriteRecordProps failed: 0x%lx.\r\n"),
                  GetLastError()));
        hr = HRESULT_FROM_WIN32(GetLastError());
    }
    
Exit:
    return hr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -