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

📄 calldetailsdialog.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            break;
        }

        hr = cpUnk->QueryInterface(
            IID_IExchangeClientGALSearchInformation,
            (void**)&cpGalInfo
            );
        if (FAILED(hr))
        {
            break;
        }
        
        hr = cpGalInfo->GetSMTPAddress(
            GalEmail,
            _countof(GalEmail)
            );
        if (FAILED(hr) || !GalEmail[0])
        {
            continue;
        }

        //first compare the aliases, then verify the
        //domain.com portion of the address
        if (! ConvertEmailAddressToAliasAndDomain(
            GalEmail,
            &pDomainGal
            ))
        {
            continue;
        }
        
        if (
            (wcsicmp(GalEmail, pContactEmail) == 0) &&
            (wcsicmp(pDomainGal, pDomainContact) == 0)
            )
        {
            //ccomptr does addref for us
            m_cpGalInfo = cpGalInfo;
            break;
        }
    }

    if (m_cpGalInfo != NULL)
    {
        StartFreeBusyRequest();
        hr = AddGalDisplayItems();
    }

    return hr;    
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::OnFreeBusyRequestSucceeded
    
    Handles the free busy request succeeding
    
    Returns (HRESULT): indicating success or failure
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::OnFreeBusyRequestSucceeded()
{    
    //
    //  Disable redraw.
    //
    SendMessage( 
        m_Dialog,              
        WM_SETREDRAW,             
        FALSE,
        0
        );    

    //
    //  Delete the old "name" item - which always comes first
    //
    SendMessage(
        m_Listbox,
        LB_DELETESTRING, 
        0, 
        0
        );     

    //
    //  if we had a call record, then delete the previous "freebusycallrecord display item" as well
    //
    if (m_cpCallRecord != NULL)
    {
        SendMessage(
            m_Listbox,
            LB_DELETESTRING, 
            0, 
            0
            );     
    }

    //
    //  Add the item    
    //
    HRESULT hr = AddFreeBusyDisplayItem();

    SendMessage( 
        m_Dialog,              
        WM_SETREDRAW,             
        TRUE,
        0
        );        
    return hr;    
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::OnAddToSpeedDial
    
    Generates the correct speed dial entry for this user based on selection
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::OnAddToSpeedDial()
{

    HRESULT             hr             = S_OK;    
    PH_SPEEDDIAL_ENTRY  SpeedDialEntry = {0};
    SpeedDialEntry.StructSize = sizeof(SpeedDialEntry);
    
    //
    // Generate the caller info 
    //
    hr = GenerateCallerInfoBySelection(
        SpeedDialEntry.pNumber, 
        _countof(SpeedDialEntry.pNumber),
        SpeedDialEntry.pName, 
        _countof(SpeedDialEntry.pName)
        );       
    if(FAILED(hr))
    {
        return hr;
    }
    
    return PhInfoGlobalData_t::pPhInfoApp->AddToSpeedDial(&SpeedDialEntry);
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::GenerateCallerInfoBySelection
    
    Generates the default username, uri for the user, based on the selection
    in the listbox
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::GenerateCallerInfoBySelection(
    WCHAR* pUri, 
    UINT   UriLength,
    WCHAR* pName, 
    UINT   NameLength    
    )
{
    if (pUri == NULL || UriLength == 0 || pName == NULL || NameLength == 0)
    {
        ASSERT(FALSE);
        return E_INVALIDARG;
    }
    
    HRESULT                  hr            = S_OK;
    CLabeledInfoDisplayItem* pCookiedItem  = NULL;
    DWORD                    Cookie        = 0;
    ce::auto_bstr            Uri;
    INT                      SelectedIndex;


    
    //always start with the same display name and add extra chars as necessary
    hr = GenerateDisplayName(
        pName, 
        NameLength
        );
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }
    
    SelectedIndex = m_Listbox.GetCurSel();
    //if there is a call record, and the call record is selected - use the
    //number from the call record and the default name
    if (m_cpCallRecord != NULL && SelectedIndex == 0)
    {
        hr = m_cpCallRecord->get_URI(&Uri);
        if (FAILED(hr) || Uri == NULL || Uri[0] == 0)
        {
            ASSERT(FALSE);
            COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to read URI from the call record. hr = 0x%x", hr));   
            return hr;
        }

        StringCchCopy(
            pUri,
            UriLength,
            Uri
            );
        return hr;
    }

    //otherwise check the cookied values
    pCookiedItem = static_cast<CLabeledInfoDisplayItem*>(m_Listbox.GetItem(SelectedIndex));
    if (!pCookiedItem)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    Cookie = pCookiedItem->GetCookie();    
    return GetUriBasedOnCookie(Cookie, pUri, UriLength);
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::GenerateDisplayName
    
    Generates the name to display for this user
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::GenerateDisplayName(
    WCHAR* pDisplayName, 
    UINT   DisplayNameLength
    )
{
    PREFAST_ASSERT(pDisplayName);

    *pDisplayName = NULL;
    
    HRESULT       hr;
    ce::auto_bstr Name;

    //
    // First check the call record    
    //
    if (m_cpCallRecord != NULL)
    {
        hr = m_cpCallRecord->get_FriendlyName(&Name);
        if (SUCCEEDED(hr) && Name != NULL && Name[0])
        {
            StringCchCopy(
                pDisplayName,
                DisplayNameLength,
                Name
                );
            if (pDisplayName[0]) 
            {
                return hr;
            }
        }
    }

    //
    // Check the contact
    //
    if (m_cpContact != NULL)
    {
        hr = m_cpContact->get_FileAs(&Name);
        if (SUCCEEDED(hr) && Name != NULL && Name[0])
        {
            StringCchCopy(
                pDisplayName,
                DisplayNameLength,
                Name
                );
            if (pDisplayName[0])
            {
                return hr;
            }
        }
    }

    //
    // Check the the gal
    //
    if (m_cpGalInfo != NULL)
    {
        hr = m_cpGalInfo->GetDisplayName(pDisplayName, DisplayNameLength);
        if (SUCCEEDED(hr) && pDisplayName[0])
        {
            return hr;
        }
    }

    //
    //  Otherwise we don't have a name for this user
    //
    return S_FALSE;
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::GetUriBasedOnCookie
    
    Get the correct phone number based on selected item
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::GetUriBasedOnCookie(
    DWORD  Cookie, 
    WCHAR* pPhoneNumber, 
    UINT   PhoneNumberLength
    )
{
    HRESULT       hr = S_OK;
    ce::auto_bstr Buffer;
    
    switch (Cookie)
    {
    case ContactHomePhone:
        hr = m_cpContact->get_HomeTelephoneNumber(&Buffer);
        break;
        
    case ContactMobilePhone:
        hr = m_cpContact->get_MobileTelephoneNumber(&Buffer);
        break;

    case ContactWorkPhone:
        hr = m_cpContact->get_BusinessTelephoneNumber(&Buffer);
        break;
        
    case GalPhoneNumber:
        return m_cpGalInfo->GetPhoneNumber(pPhoneNumber, PhoneNumberLength);
        break;
        
    case ContactEmailAddr:
    case ContactHomeAddr:
    case ContactName:
    case ContactWorkAddr:
    case GalEmailAddress:
    case GalName:
    case GalOfficeNumber:
    default:
        return GenerateDefaultPhoneNumber(pPhoneNumber, PhoneNumberLength);
    }

    if (SUCCEEDED(hr) && Buffer != NULL && Buffer[0])
    {
        StringCchCopy(
            pPhoneNumber,
            PhoneNumberLength,
            Buffer
            );
    }

    return hr;
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::GenerateDefaultPhoneNumber
    
    In the absence of a user-selection, generates the default 
    phone number for this user
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::GenerateDefaultPhoneNumber(
    WCHAR* pPhoneNumber, 
    UINT   PhoneNumberLength
    )
{
    HRESULT       hr;
    ce::auto_bstr Buffer;

    //
    //  First check the call record    
    //
    if (m_cpCallRecord != NULL)
    {
        hr = m_cpCallRecord->get_URI(&Buffer);
        if (SUCCEEDED (hr) && Buffer != NULL && Buffer[0])
        {
            StringCchCopy(
                pPhoneNumber, 
                PhoneNumberLength, 
                Buffer
                );
            return hr;
        }
    }

    //
    // The order goes - home phone, work phone, mobile phone
    //
    if (m_cpContact != NULL)
    {
        hr = m_cpContact->get_HomeTelephoneNumber(&Buffer);
        if (SUCCEEDED(hr) && Buffer != NULL && Buffer[0])
        {
            goto exit;
        }
        hr = m_cpContact->get_BusinessTelephoneNumber(&Buffer);
        if (SUCCEEDED(hr) && Buffer != NULL && Buffer[0])
        {
            goto exit;
        }
        hr = m_cpContact->get_MobileTelephoneNumber(&Buffer);
        if (SUCCEEDED(hr) && Buffer != NULL && Buffer[0])
        {
            goto exit;
        }
    }

    ///
    // Last resort - check the gal number
    //
    if (m_cpGalInfo != NULL)
    {
        return m_cpGalInfo->GetPhoneNumber(pPhoneNumber, PhoneNumberLength);
    }

    return S_FALSE;

exit:
    
    StringCchCopy(
        pPhoneNumber,
        PhoneNumberLength,
        Buffer
        );    
    return hr;
}



/*------------------------------------------------------------------------------
    OnDial
    
    Place a call in the phone app with the number specified in the 
    call log record we retrived. 
------------------------------------------------------------------------------*/
HRESULT
CallDetailsDialog_t::OnDial(
    void
    )
{
    HRESULT hr            = S_OK;

    PH_MAKEPHONECALL_PARAMETERS Parameters = {0};
    Parameters.StructSize = sizeof(Parameters);    
    
    //
    // Generate the caller info 
    //    
    hr = GenerateCallerInfoBySelection(
        Parameters.DestAddress,
        _countof(Parameters.DestAddress),
        Parameters.CalledParty, 
        _countof(Parameters.CalledParty)
        );   

    if (FAILED(hr))
    {
        return hr;
    }
    return PHMakePhoneCall(&Parameters);
}

⌨️ 快捷键说明

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