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

📄 speeddialeditdialog.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    //Set the text and add the item
    return pItem->SetText(Value);
}

/*------------------------------------------------------------------------------
    SpeedDialEditDialog_t::GetRingtoneIndex
    
    Gets the index corresponding to the currently selected ringtone
------------------------------------------------------------------------------*/
HRESULT SpeedDialEditDialog_t::GetRingtoneIndex(
    const WCHAR *pRingtone
    )
{
    WCHAR Check [200] = L"", 
          Buffer[200] = L"";
    

    //Convert this ringtone to a file name    
    HRESULT hr = m_RingtoneIterator.PathToFileName(
        pRingtone, 
        Buffer,
        _countof(Buffer)
        );
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        goto error;
    }

    //check each ringtone
    for (INT i = 0; i < m_RingtoneIterator.GetRingtoneCount(); i++)
    {
        hr = m_RingtoneIterator.GetRingtoneAt(
            i, 
            Check,
            _countof(Check)
            );
        if (FAILED(hr))
        {
            ASSERT(FALSE);
            goto error;
        }

        if (wcsicmp(Check, Buffer) == 0)
        {
            m_RingtoneIndex = i;
            return S_OK;
        }
    }

    hr = E_FAIL;
    
error:
    m_RingtoneIndex = DEFAULT_RINGTONE;
    return hr;
}

/*------------------------------------------------------------------------------
    SpeedDialEditDialog_t::GetRingtoneText
    
    Gets the text that should be displayed in the ringtone item
------------------------------------------------------------------------------*/
HRESULT SpeedDialEditDialog_t::GetRingtoneText(
    WCHAR *pBuffer, 
    UINT   BufferLen
    )
{
    if (m_RingtoneIndex < 0 || m_RingtoneIndex >= m_RingtoneIterator.GetRingtoneCount())
    {
        m_RingtoneIndex = DEFAULT_RINGTONE;
    }
    
    if (m_RingtoneIndex == DEFAULT_RINGTONE)
    {
        StringCchCopy(
            pBuffer,
            BufferLen,
            CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_LABEL_DEFAULTRINGTONE)
            );
        return S_OK;
    }

    return m_RingtoneIterator.GetRingtoneAt(
        m_RingtoneIndex,
        pBuffer, 
        BufferLen
        );
}

/*------------------------------------------------------------------------------
    SpeedDialEditDialog_t::UpdateStatusRegion
    
    Updates the status region with the current items status string
    
    Returns (HRESULT): indicating success or failure
------------------------------------------------------------------------------*/
HRESULT SpeedDialEditDialog_t::UpdateStatusRegion()
{
    int SelectedIndex = 0;
    SelectedIndex = m_Listbox.GetCurSel();
    if (SelectedIndex < 0 || SelectedIndex >= _countof(SettingsArray))
    {
        return S_FALSE;
    }

    //first add the status notification
    STATUS_HEADER_PARAMETERS    StatusParams = {0};
    StatusParams.Cookie     = NotificationCookie;
    StatusParams.Instance   = GlobalData_t::s_ModuleInstance;
    StatusParams.Priority   = shpNodeHelp;
    StatusParams.ResourceId = SettingsArray[SelectedIndex].HelpString;
    StatusParams.secTimeout = INFINITE;

    return (HRESULT)SendMessage(
        m_StatusRegion, 
        WM_STATUSHEADER_ADDSTATUSNOTIFICATION,
        (WPARAM)sizeof(STATUS_HEADER_PARAMETERS),
        (LPARAM)&StatusParams
        );
}

/*------------------------------------------------------------------------------
    SpeedDialEditDialog_t::UpdateMenuBar
    
    Update the menu bar based on the currently selected item
------------------------------------------------------------------------------*/
HRESULT SpeedDialEditDialog_t::UpdateMenuBar()
{
    int SelectedIndex = m_Listbox.GetCurSel();
    int MenuId;
    
    switch (SelectedIndex)
    {
    case ItemName:
    case ItemUri:
        MenuId = IDMB_SPEEDDIALEDIT_TEXT; 
        break;
            
    case ItemRingtone:
        MenuId = IDMB_SPEEDDIAL_RINGTONE; 
        break;
        
    case ItemSpeedDialIndex:
        MenuId = IDMB_SPEEDDIALEDIT_INDEX; 
        break;

    default:
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    HRESULT hr = m_MenuBar.SetMenu(
        GlobalData_t::s_ModuleInstance, 
        MenuId
        );

    ShowHideBackspaceButton();

    return hr;
}

VOID
SpeedDialEditDialog_t::ShowHideBackspaceButton()
{
    int               SelectedIndex = 0;
    IVoIPDisplayItem* pItem         = NULL;
    WCHAR             Text[3]       = L"";
        
    SelectedIndex = m_Listbox.GetCurSel();

    //now update the context buttons
    pItem = m_Listbox.GetItem(SelectedIndex);
    if (! pItem)
    {
        ASSERT(FALSE);
        return;
    }

    //determine if there is text in the item
    pItem->GetText(Text, _countof(Text));

    int IdShow;
    bool Show;
    
    switch (SelectedIndex)
    {
    case ItemName:
    case ItemUri:
    case ItemSpeedDialIndex:
        IdShow = IDC_BACKSPACE; 
        Show = (Text[0] != 0);
        break;
            
    case ItemRingtone:
        IdShow = IDC_CHANGERINGTONE;
        Show = (m_RingtoneIterator.GetRingtoneCount() > 0);
        break;
        
    default:
        ASSERT(FALSE);
        return;
    }

    m_MenuBar.ShowMenuButton(
        IdShow, 
        Show
        );
    return;
}

/*------------------------------------------------------------------------------
    SpeedDialEditDialog_t::OnChangeRingtone

    Handles the user pressing the "change ringtone" context button
------------------------------------------------------------------------------*/
HRESULT SpeedDialEditDialog_t::OnChangeRingtone()
{
    IVoIPDisplayItem* pItem = NULL;
    
    pItem = m_Listbox.GetItem(ItemRingtone);
    if (! pItem)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }
    
    //if we are at the end of the ringtone array - wrap back around (to default)
    if (m_RingtoneIndex == m_RingtoneIterator.GetRingtoneCount()-1)
    {
        m_RingtoneIndex = DEFAULT_RINGTONE;

        //stop playing a sound...
        PlaySound(
            NULL, 
            NULL, 
            0
            );
    }
    else
    {
        //otherwise, get the ringtone to play and play it
        m_RingtoneIndex++;
        WCHAR Path[MAX_PATH] = L"";
        WCHAR Tone[100]      = L"";

        m_RingtoneIterator.GetRingtoneAt(
            m_RingtoneIndex, 
            Tone, 
            _countof(Tone)
            );
        
        m_RingtoneIterator.ConstructPath(
            Tone,
            Path, 
            _countof(Path)
            );
        
        PlaySound(
            Path,
            NULL,
            SND_FILENAME | SND_ASYNC | SND_NODEFAULT
            );
    }

    WCHAR Text[100] = L"";
    RECT  ItemRect  = {0};
    
    GetRingtoneText(
        Text, 
        _countof(Text)
        );

    //update the item text
    pItem->SetText(Text);

    //refresh the item
    m_Listbox.GetItemRect(ItemRingtone, &ItemRect);
    InvalidateRect(m_Listbox, &ItemRect, FALSE);
    
    return S_OK;
}

/*------------------------------------------------------------------------------
    SpeedDialEditDialog_t::SaveAndExit
    
    Saves all the users settings, validates and exits.
------------------------------------------------------------------------------*/
HRESULT SpeedDialEditDialog_t::SaveProperties()
{
    ce::auto_bstr Property;
    WCHAR         Buffer[100] = L"";
    bool          HasName     = false;
    
    //get the user value for each setting, validate and then persist to the
    //caller info record
    for (INT i = 0; i < _countof(SettingsArray); i++)
    {
        Property = NULL;

        //get the item from the list
        IVoIPDisplayItem* pItem = m_Listbox.GetItem(i);
        if (! pItem)
        {
            ASSERT(FALSE);
            return E_UNEXPECTED;
        }

        pItem->GetText(
            Buffer, 
            _countof(Buffer)
            );

        //based on cookie (same as list box index), determine if the given text is valid
        switch (i)
        {
        case ItemUri:
            if (! Buffer[0])
            {
                //if there is no URI but there is a name show an error
                if (HasName)
                {
                    ShowError(
                        IDS_ERROR_SPEEDDIAL_NEED_URI, 
                        IDMB_MSGBOX_ERROR,
                        false
                        );
                    m_Listbox.SetCurSel(i);
                    return E_FAIL;
                }

                //otherwise there is no name or URI, just cancel
                Exit();
                return S_FALSE;
            }

            Property = SysAllocString(Buffer);
            if (! Property)
            {
                return E_OUTOFMEMORY;
            }

            //persist it in the record
            m_cpRecord->put_URI(Property);
            break;

        case ItemName:
            //remember if there is a name or not...
            HasName = (Buffer[0] != 0);
            
            Property = SysAllocString(Buffer);
            if (! Property)
            {
                return E_OUTOFMEMORY;
            }

            m_cpRecord->put_FriendlyName(Property);
            break;

        case ItemSpeedDialIndex:
            {
                int SpeedDial;
                CComPtr<IVoIPCallerInfoRecord>  cpExistingRecord;
                
                //validate speed dial index
                if (! Buffer[0])
                {
                    SpeedDial = m_SpeedDialIndex;
                }
                else
                {
                    SpeedDial = _wtoi(Buffer);
                }

                //this should be enforced by the edit control
                if (SpeedDial < c_idxSpeedDialMin || SpeedDial > c_idxSpeedDialMax)
                {
                    ASSERT(FALSE);

                    ShowError(
                        IDS_ERROR_SPEEDDIAL_INVALID, 
                        IDMB_MSGBOX_ERROR,
                        false
                        );

                    m_Listbox.SetCurSel(i);
                    return S_FALSE;
                }

                //if the speed dial entry has changed, validate it is available
                if (m_SpeedDialIndex != SpeedDial)
                {
                    if (SUCCEEDED(m_cpCallerInfoDB->FindCallerInfoBySpeedDialEntry(SpeedDial, &cpExistingRecord)))
                    {
                        ShowError(
                            IDS_ERROR_SPEEDDIAL_INUSE,
                            IDMB_MSGBOX_ERROR,
                            false
                            );
                        m_Listbox.SetCurSel(i);
                        return S_FALSE;
                    }
                }

                //persist the value
                m_cpRecord->put_SpeedDialEntry(SpeedDial);
            }
            break;

        case ItemRingtone:
            if (m_RingtoneIndex == DEFAULT_RINGTONE)
            {
                Property = SysAllocString(L"");
            }
            else
            {
                WCHAR Path[MAX_PATH] = L"";
                WCHAR Tone[100]      = L"";
                
                m_RingtoneIterator.GetRingtoneAt(
                    m_RingtoneIndex, 
                    Tone, 
                    _countof(Tone)
                    );
                m_RingtoneIterator.ConstructPath(
                    Tone, 
                    Path,
                    _countof(Path)
                    );
                Property = SysAllocString(Path);
            }

            m_cpRecord->put_RingTone(Property);
            break;

        default:
            ASSERT(FALSE);
            return E_UNEXPECTED;
        }
        
    }

    //all values pass - write the record to the database and exit this state
    HRESULT hr = m_cpRecord->Commit();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
    }

    //still exit...
    return S_OK;
}


⌨️ 快捷键说明

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