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

📄 volumesettings.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 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.
//
#include "settingsApp.hpp"
#include "VolumeSettings.hpp"
#include "resource.h"
#include "ControlDefinitions.h"
#include "Controls.hpp"
#include "VoIPNotify.hpp"
#include "LabeledTrackBarDisplayItem.hpp"
#include "Layout.hpp"

const WCHAR c_SpeakerVolumePath[] = L"\\Windows\\beep.wav";

VolumeSettingsDialog_t::VolumeSettingsDialog_t()
{
    // Save the old volumes
    for(INT i = 0; i < c_VolumeSettings; i++)
    {
        m_OldVolume[i] = PHGetVolumeSetting(c_rgSettings[i].VolumeSetting);
    }

    m_IsAGCEnabled = PHGetSetting(phsDisableAGC) ? false : true;
}

VolumeSettingsDialog_t::~VolumeSettingsDialog_t()
{
}

HRESULT 
VolumeSettingsDialog_t::CreateDialogScreen(
    )
{
    return SettingsDialog_t::CreateDialogScreen(
        IDS_VOLUMESETTINGS_HEADER,
        IDS_VOLUMESETTINGS_TITLE,
        IDMB_VOLUMESETTINGS_BUTTONS,
        PHSETTINGS_VOLUMESETTINGS_SCREEN_ID
        );
}

HRESULT 
VolumeSettingsDialog_t::OnUpdate(
    void
    )
{
    ListBox_t ListBox;
    ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
    UINT ItemCount = ListBox.GetCount();
    LabeledTrackBarDisplayItem_t *pItem = NULL;
    HRESULT         hr = S_OK;
    PHVolumeSetting VolumeType;

    for(INT i = 0; i < ItemCount; i++)
    {
        pItem = static_cast<LabeledTrackBarDisplayItem_t*>(ListBox.GetItem(i));
        VolumeType = static_cast<PHVolumeSetting>(pItem->GetCookie()); 
        if ((VolumeType == phvsMicrophoneVolume) && 
            (m_IsAGCEnabled))
        {
            ASSERT(FALSE); 
            return E_FAIL;
        }
        hr = PHSetVolume(VolumeType, pItem->GetTrackbarPosition()); 
        if (FAILED(hr))
        {
            ASSERT(FALSE);
            return hr;
        }
    }

    return hr; 
}

HRESULT 
VolumeSettingsDialog_t::Initialize(
    )
{ 
    LabeledTrackBarDisplayItem_t *pItem = NULL;
    ListBox_t ListBox;
    ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);

    HRESULT hr = S_OK;

    //clear the display
    hr = OnResetContent();
    if (FAILED(hr))
    {
        goto exit;
    }

    //add a trackbar display item for each setting
    for (UINT Index = 0; Index < c_VolumeSettings; Index++)
    {
        if ((c_rgSettings[Index].VolumeSetting == phvsMicrophoneVolume) && 
            (m_IsAGCEnabled))
        {
            continue; 
        }

        const VolumeSettingData *c_pSetting = &c_rgSettings[Index];
        pItem = new LabeledTrackBarDisplayItem_t(
            CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, c_pSetting->IdLabel),
            Layout_t::TrackBarLabelWidth()
            );
        if (! pItem)
        {
            ASSERT(FALSE);
            hr = E_OUTOFMEMORY;
            goto exit;
        }

        //boundaries go from 0-10
        hr = pItem->SetTrackbarBoundaries(c_MinUIVolume, c_MaxUIVolume);
        if (FAILED(hr))
        {
            goto exit;
        }

        //set the current position of the slider in the trackbar
        hr = pItem->SetTrackbarPosition(m_OldVolume[Index]);
        if (FAILED(hr))
        {
            goto exit;
        }

        //add cookie
        hr = pItem->SetCookie(
            c_rgSettings[Index].VolumeSetting
            );
        if(FAILED(hr))
        {
            goto exit;
        }

        //add the item to the list
        hr = ListBox.AddItem(
            -1, 
            pItem
            );
        if (FAILED(hr))
        {
            goto exit;
        }          
    }

    SendMessage(ListBox, LB_SETCURSEL, 0, 0);

exit:
    //if adding items failed, we need to delete the added items - resetcontent will take
    //care of that for us
    if (FAILED(hr))
    {
        if (pItem)
        {
            delete pItem;
        }
        ASSERT(FALSE);
        OnResetContent();
    }

    return hr;
}

HRESULT 
VolumeSettingsDialog_t::OnCommand(
    WPARAM              wParam
    )
{ 
    INT i;
    switch (wParam) 
    {
    case IDOK:
        OnUpdate();
        return GetSettingsApp()->GoBackToPreviousScreen();
    case IDCANCEL:
        // disgard changes, and restore old volumes
        for(i = 0; i < c_VolumeSettings; i++)
        {
            if ((c_rgSettings[i].VolumeSetting == phvsMicrophoneVolume) && 
                (m_IsAGCEnabled))
            {
                continue;
            }
            PHSetVolume(c_rgSettings[i].VolumeSetting, m_OldVolume[i]);
        }
        
        return GetSettingsApp()->GoBackToPreviousScreen();  
    }    
    return S_OK;
}

/*------------------------------------------------------------------------------
    VolumeSettingsDialog_t::OnChildControlUpdate
    
    Handles a child control (trackbar) updating its item
------------------------------------------------------------------------------*/
HRESULT 
VolumeSettingsDialog_t::OnChildControlUpdate(
    void
    )
{

    ListBox_t ListBox;
    ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
    LabeledTrackBarDisplayItem_t *pItem = NULL;
    HRESULT       hr = S_OK;

    int SelectedIndex = SendMessage(
                            ListBox, 
                            LB_GETCURSEL, 
                            0, 0
                            ); 
    if (SelectedIndex < 0 || SelectedIndex >= ListBox.GetCount())
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }
    pItem = static_cast<LabeledTrackBarDisplayItem_t*>(ListBox.GetItem(SelectedIndex)); 
    if (! pItem)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    PHVolumeSetting VolumeType = static_cast<PHVolumeSetting>(pItem->GetCookie());
    hr = PHSetVolume(VolumeType, pItem->GetTrackbarPosition());
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }

    //play the sound feedback for volume change
    PlayVolumeFeedback(VolumeType); 

    return hr;
}

/*------------------------------------------------------------------------------
    VolumeSettingsDialog_t::OnFunctionKey
    
    Handles a hotkey press of volume up/down
------------------------------------------------------------------------------*/
HRESULT 
VolumeSettingsDialog_t::OnFunctionKey(
    LPARAM      lParam
    )
{
    bool        VolumeIncrease   = false;
    ListBox_t   ListBox;
    ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);
    LabeledTrackBarDisplayItem_t *pItem = NULL;
    HRESULT     hr = S_OK;

    //we only handle the hotkey press if it was volume up/down
    switch (HIWORD(lParam))
    {
    case VK_UP:
        VolumeIncrease = true;
        break;

    case VK_DOWN:
        VolumeIncrease = false;
        break;

    default:
        return S_FALSE;
    }

    //find the trackbar item associated with this hotkey press
    int SelectedIndex = SendMessage(
                            ListBox, 
                            LB_GETCURSEL, 
                            0, 0
                            ); 
    if (SelectedIndex < 0 || SelectedIndex >= ListBox.GetCount())
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    pItem = static_cast<LabeledTrackBarDisplayItem_t*>(ListBox.GetItem(SelectedIndex)); 
    if (! pItem)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    //increment (or decrement) the volume setting
    INT NewTrackbarPosition = (VolumeIncrease) ?
           pItem->GetTrackbarPosition() + 1 :
           pItem->GetTrackbarPosition() - 1;
    NewTrackbarPosition = max(min(NewTrackbarPosition, 
                                  (INT)c_MaxUIVolume), 
                              (INT)c_MinUIVolume);

    hr = pItem->SetTrackbarPosition(NewTrackbarPosition);
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }

    PHVolumeSetting VolumeType = static_cast<PHVolumeSetting>(pItem->GetCookie());
    //update the trackbar position
    hr = PHSetVolume(VolumeType, pItem->GetTrackbarPosition());
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }

    //play the sound feedback for volume change
    PlayVolumeFeedback(VolumeType); 

    return hr;
}

/*------------------------------------------------------------------------------
    VolumeSettingsDialog_t::PlayVolumeFeedback
    
    Helper function that plays the sound feedback for the volume change
------------------------------------------------------------------------------*/
HRESULT 
VolumeSettingsDialog_t::PlayVolumeFeedback(
    PHVolumeSetting           volumeSetting
    )
{
    // if there is any call on going, we don't give feedback
    DWORD PhoneAppState = PHGetSetting(phsPhoneAppStatus); 
    if (PhoneAppState & VOIP_PHONEAPP_ACTIVE_BITMASK)
    {
        return S_FALSE;
    }

    PHActiveVolumeMode OldPhoneActiveMode = PHGetActiveVolume(); 
    PHActiveVolumeMode NewPhoneActiveMode;
    BOOL    Play = FALSE;  
    switch (volumeSetting)
    {
        case phvsSpeakerVolume:
            NewPhoneActiveMode = SpeakerVolumeMode;
            Play = TRUE;
            break;
        case phvsRingerVolume:           
            NewPhoneActiveMode = RingerVolumeMode;
            Play = TRUE;
            break;           
        case phvsHandsetVolume:
        case phvsMicrophoneVolume:
            Play = FALSE;
            break;
        default:
            ASSERT(FALSE);
            return E_UNEXPECTED;
    }

    if (Play)
    {
        PHSetActiveVolume(NewPhoneActiveMode);
        PlaySound(
            c_SpeakerVolumePath,
            NULL,
            SND_FILENAME | SND_ASYNC | SND_NODEFAULT
            );
        Sleep(250);
        PHSetActiveVolume(OldPhoneActiveMode);
    }

    return S_OK;

}

⌨️ 快捷键说明

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