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

📄 gallistdialog.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        IID_IVoIPLabeledEditDisplayItem, 
        (void**)&pSearchEditDisplayItem
        ); 
    if (FAILED(hr))
    {
        return hr;
    }
    
    hr = pSearchEditDisplayItem->SetLabelText(pSearchTitle); 
    if (FAILED(hr))
    {
        return hr;
    }

    RECT ItemRect = {0}; 
    m_Listbox.GetItemRect(0, &ItemRect);
    InvalidateRect(m_Listbox, &ItemRect, TRUE); 

    UpdateStatus();
    
    //
    //  After changing the search filter, if there is an input text the edit box
    //  then add a timer to initiate an exchange query.
    //
    if (m_QueryValue.length() > 0)
    {
        m_RefreshNeeded = true;
        return UpdateTimer();
    }
    return S_OK;
}

/*------------------------------------------------------------------------------
    GalListDialog_t::AddSearchInputListBox

    This function adds the search edit control. 
------------------------------------------------------------------------------*/
HRESULT 
GalListDialog_t::AddSearchInputListBox(
    void
    )
{
    IVoIPDisplayItem* pVoipDisplayItem;
    
    UINT FilterNameResourceId;
    switch (m_FilterType)
    { 
        case LastName:
            FilterNameResourceId = IDS_LABEL_LASTNAME;
            break;
            
        case FirstName:
            FilterNameResourceId = IDS_LABEL_FIRSTNAME;
            break;
            
        case Alias:
            FilterNameResourceId = IDS_LABEL_ALIAS;
            break;

        default:
            ASSERT (FALSE);
            return E_FAIL;
    }

    //
    //  Read the title from the resource.
    //
    const WCHAR* pSearchTitle = CommonUtilities_t::LoadString (
        GlobalData_t::s_ModuleInstance, 
        FilterNameResourceId
        );
    
    HRESULT hr = PHCreateLabeledEditDisplayItem(
        pSearchTitle,
        WS_BORDER,
        -1,
        &pVoipDisplayItem,
        -1
        );
    
    if (FAILED(hr))
    {
        return hr;
    }

    pVoipDisplayItem->SetText(
        m_QueryValue
        );

    hr = m_Listbox.AddItem (0, pVoipDisplayItem);
    if (FAILED(hr))
    {
        delete pVoipDisplayItem;
    }
    return hr;
}

/*------------------------------------------------------------------------------
    GalListDialog_t::CreateExchangeRequest
    
    Initiates an exchange request
------------------------------------------------------------------------------*/
HRESULT 
GalListDialog_t::CreateExchangeRequest(
    void
    )
{
    if(m_RefreshNeeded == false)
    {
        return S_FALSE;
    }

    //
    //  Create a query only if there is text in the query edit control.
    //
    if (m_QueryValue.length() == 0)
    {
        return S_FALSE;
    }


    HRESULT hr = PhInfoGlobalData_t::pPhInfoApp->GetExchangeClient(&m_cpExchangeClient);
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to get exchange client. hr = 0x%x", hr));   
        return hr;
    }

    GALSearchCriteria  GalSearchCriteria = {0};   
    switch (m_FilterType)
    {
        case Alias:                     
            GalSearchCriteria.wszAlias = m_QueryValue.get_buffer();
            break;
            
        case FirstName:                     
            GalSearchCriteria.wszFirstName = m_QueryValue.get_buffer();
            break;
            
        case LastName:                     
            GalSearchCriteria.wszLastName = m_QueryValue.get_buffer();
            break;
            
        default:
            ASSERT(FALSE);
            return E_FAIL;
            break;
    }
        
    //
    // request all the contacts
    //
    hr = m_cpExchangeClient->RequestGALSearch(
        &GalSearchCriteria, 
        &m_cpExchangeRequest
        );

    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to start GAL search. hr=0x%x", hr));   
    }
    return hr;
}

/*------------------------------------------------------------------------------
    GalListDialog_t::UpdateStatus
    
    Update the status message.
------------------------------------------------------------------------------*/
HRESULT 
GalListDialog_t::UpdateStatus (
    void
    )
{
    STATUS_HEADER_PARAMETERS_EX  StatusHeaderParameter;  
    WCHAR Buffer[MAX_PATH];
    int   ExistingItemCount = m_Listbox.GetCount();    

    ZeroMemory(&StatusHeaderParameter, sizeof(STATUS_HEADER_PARAMETERS_EX)); 
    
    //
    //  Get the actual result count. Query text edit box adds a one to the listbox.
    //
    ExistingItemCount--;
    
    if (m_QueryValue.length() == 0 && ExistingItemCount == 0)
    {
        //
        //  Decide the help string to be displayed in the Status region.
        //
        int QueryHelp;
        switch (m_FilterType)
        {
            case Alias:
                QueryHelp = IDS_STATUS_GALSEARCH_DEFAULT;
                break;
                
            case FirstName:
                QueryHelp = IDS_STATUS_GALSEARCH_FIRSTNAME;
                break;
                
            case LastName:
                QueryHelp = IDS_STATUS_GALSEARCH_LASTNAME;                
                break;

            default:
                ASSERT(FALSE);
                return E_FAIL;
        }
        StatusHeaderParameter.pwszDisplayString = CommonUtilities_t::LoadString (
            GlobalData_t::s_ModuleInstance, 
            QueryHelp
            );  
    }
    else 
    {
        //
        //  Update the status bar with the result count.
        //
        const WCHAR* pSearchStatus = CommonUtilities_t::LoadString (
            GlobalData_t::s_ModuleInstance, 
            IDS_FMT_SEARCH_RESULTS
            );  

        StringCchPrintf(
            Buffer,
            _countof(Buffer),
            pSearchStatus,
            ExistingItemCount
            );
        StatusHeaderParameter.pwszDisplayString = Buffer;
    }
    
    
    StatusHeaderParameter.Instance      = GlobalData_t::s_ModuleInstance;
    StatusHeaderParameter.Priority      = shpDefault;
    StatusHeaderParameter.secTimeout    = INFINITE; 

    SendMessage(
        m_StatusRegion, 
        WM_STATUSHEADER_ADDSTATUSNOTIFICATION, 
        sizeof(StatusHeaderParameter), 
        (LPARAM)&StatusHeaderParameter
        );

    return S_OK;
}

/*------------------------------------------------------------------------------
    GalListDialog_t::DisplayGALContacts
    
    Display all the GAL contacts that the exchange query has returned.
------------------------------------------------------------------------------*/
HRESULT GalListDialog_t::DisplayGALContacts()
{
    HRESULT                     hr;
    ExchangeClientRequestStatus status;

    hr = m_cpExchangeRequest->GetStatus(&status);
    if (FAILED(hr))
    {
        return hr;
    }

    if(status != e_ecrsSucceeded)
    {
        return E_FAIL;
    }

    m_RefreshNeeded = false;
    CComPtr<IExchangeClientDataItemArray> cpExchangeDataArray;    
    hr = m_cpExchangeRequest->GetDataItemArray(&cpExchangeDataArray);
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to get data from exchange request. hr = 0x%x", hr));   
        return hr;
    }

    UINT ExchangeDataItemCount;
    WCHAR Buffer [MAX_PATH];
    
    //Turn off the redraw flag...
    SendMessage(m_Listbox, WM_SETREDRAW, FALSE, 0);

    //
    //  Clear all the previous results.
    //    
    ClearSearchResults ();

    hr = cpExchangeDataArray->GetItemCount(&ExchangeDataItemCount);    
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to get exchange data item count. hr=0x%x", hr));       
    }
    
    //
    //  Display all results.
    //    
    if(ExchangeDataItemCount)
    {
        IVoIPDisplayItem*                            pVoIPDisplayItem;
        IVoIPTextDisplayItem*                        pTextItem;
        CComPtr<IUnknown>                            cpUnknown;
        CComPtr<IExchangeClientGALSearchInformation> cpGalInformation;
        
        for (int i = 0; i < ExchangeDataItemCount; i++)
        {        
            hr = cpExchangeDataArray->GetItemAt(i, &cpUnknown);
            if (FAILED(hr))
            {
                COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to get exchange data item at %d. hr=0x%x", i, hr));       
                continue;
            }

            //
            //  Read GAL contact display name.
            //
            hr = cpUnknown->QueryInterface(IID_IExchangeClientGALSearchInformation, (void**)&cpGalInformation);
            if (FAILED(hr))
            {
                continue;
            }
            
            hr = cpGalInformation->GetDisplayName (Buffer, _countof(Buffer));
            if (FAILED(hr))
            {
                COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to get display name. hr=0x%x", hr));
                continue;
            }        
            
            
            hr = PHCreateTextDisplayItem(Buffer, &pVoIPDisplayItem);    
            if (FAILED(hr))
            {
                COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to create text display item. hr=0x%x", hr));
                continue;
            }
            
            pVoIPDisplayItem->QueryInterface(IID_IVoIPTextDisplayItem, (void**)&pTextItem);
            if (!pTextItem)
            {
                ASSERT(FALSE);
                delete pVoIPDisplayItem;
                continue;
            }
            
            //
            //  Store the COM ptr in the display item.
            //
            hr = pTextItem->SetComPtr(cpGalInformation);
            if (FAILED(hr))
            {
                COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to store the GAL com pointer in the display item. hr=0x%x", hr));
            }
           
            hr = m_Listbox.AddItem(-1, pVoIPDisplayItem);    
            if (FAILED(hr))
            {
                COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to add GAL item to the list box. hr=0x%x", hr));
                delete pVoIPDisplayItem;
                continue;
            }        
        }
    }
    
    UpdateStatus ();
    SendMessage(m_Listbox, WM_SETREDRAW, TRUE, 0);
    return hr;
}

/*------------------------------------------------------------------------------
    GalListDialog_t::ClearSearchResults 
    
    Clear the listbox except for the first item. First item is the search edit box
------------------------------------------------------------------------------*/
void
GalListDialog_t::ClearSearchResults (
    void
    )
{
    int ExistingItemCount = m_Listbox.GetCount();

    //
    //  Clear the listbox except for the first item 
    //
    while (ExistingItemCount > 1)
    {
        SendMessage(m_Listbox, LB_DELETESTRING, 1, 0);
        ExistingItemCount--;
    }
    return;
}

⌨️ 快捷键说明

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