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

📄 viewserversettings.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 "ViewServerSettings.hpp"
#include "ServerSettings.hpp"
#include "SettingsApp.hpp"
#include "resource.h"
#include "ControlDefinitions.h"
#include "Controls.hpp"
#include "VoIPNotify.hpp"
#include "DisplayItem.hpp"

ViewServerSettingsDialog_t::ViewServerSettingsDialog_t()
{
}

ViewServerSettingsDialog_t::~ViewServerSettingsDialog_t()
{
}

HRESULT 
ViewServerSettingsDialog_t::CreateDialogScreen(
    )
{
    return SettingsDialog_t::CreateDialogScreen(
        IDS_EMPTY,
        IDS_SERVERSETTINGS_TITLE,
        IDMB_SERVERSETTINGS_VIEW_BUTTONS,
        PHSETTINGS_SERVERSETTINGS_SCREEN_ID
        );
}

HRESULT 
ViewServerSettingsDialog_t::Initialize(
    void
    )
{ 
    HRESULT hr = S_OK;
    
    ServerSettings_t    ServerSettings;
    hr = ServerSettings.RetrieveSettingsFromProvision();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }

    //get the hidden password string
    ce::wstring HiddenPassword;
    HiddenPassword.clear();

    UINT BufferSize = ServerSettings_t::s_ServerSettings[ServerSettings_t::Password].length();
    while (BufferSize--)
    {
        HiddenPassword.append(L"*");
    }

    //add each item to the listbox
    ListBox_t   ListBox; 
    ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);

    ce::wstring ItemText; 
    for (unsigned int SettingIndex = 0; SettingIndex < ServerSettings_t::sc_ServerSettingsItems; SettingIndex++)
    {
        if (ServerSettings_t::s_ServerSettings[SettingIndex].length() == 0)
        {
            continue; 
        }

        ItemText.clear(); 
        
        if (!ItemText.assign(CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, ServerSettings_t::sc_ServerSettings[SettingIndex].LabelId)))
        {
            hr = E_OUTOFMEMORY; 
            break; 
        }

        if (!ItemText.append(L" ")) //insert a single space between name and value
        {
            hr = E_OUTOFMEMORY; 
            break; 
        }

        if (!ItemText.append((SettingIndex == ServerSettings_t::Password) ? HiddenPassword : ServerSettings_t::s_ServerSettings[SettingIndex]))
        {
            hr = E_OUTOFMEMORY; 
            break; 
        }
        
        IVoIPDisplayItem* pItem = NULL;
        hr = PHCreateTextDisplayItem(
                ItemText.get_buffer(), 
                &pItem
                );
        if (FAILED (hr))
        {
            break; 
        }

        IVoIPTextDisplayItem* pTextItem = NULL; 
        pItem->QueryInterface(IID_IVoIPTextDisplayItem, (void**)&pTextItem);
        if (pTextItem == NULL)
        {
            ASSERT(FALSE);
            delete pItem;
            continue;
        }

        pTextItem->SetCookie(SettingIndex);         
        
        hr = ListBox.AddItem(-1, pItem);
        if (FAILED(hr))
        {
            delete pItem;
            break; 
        }
    }

    SendMessage(ListBox, LB_SETCURSEL, 0, 0);
    UpdateStatusHeader();
  
    return hr;
}

HRESULT 
ViewServerSettingsDialog_t::OnCommand(
    WPARAM              wParam
    )
{ 
    HRESULT hr = S_OK;
    if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LISTBOX)
    {
        hr = UpdateStatusHeader();
        if (FAILED(hr))
        {
            goto exit;
        }
        return hr;
    }
    switch (wParam) 
    {
    case IDOK:
        return GetSettingsApp()->GoBackToPreviousScreen();
        
    case IDC_EDITSERVER:
        return GetSettingsApp()->CreateNewWindow(SettingsApp_t::IdEditServerSettings);
    }    
    return S_OK;

exit:
    ASSERT(FALSE);
    return hr;
}

HRESULT
ViewServerSettingsDialog_t::UpdateStatusHeader(
    void
    )
{
    IVoIPDisplayItem*       pSelectedDisplayItem = NULL;
    ListBox_t               ListBox; 
    
    ListBox = GetDlgItem (m_DialogScreen, IDC_LISTBOX);

    int SelectedItemIndex = ListBox.GetCurSel(); 
    if (SelectedItemIndex < 0)
    {
        return S_FALSE;
    }

    pSelectedDisplayItem = ListBox.GetItem(SelectedItemIndex);
    if (pSelectedDisplayItem == NULL)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    IVoIPTextDisplayItem* pTextItem = NULL;
    pSelectedDisplayItem->QueryInterface(IID_IVoIPTextDisplayItem, (void**)&pTextItem);
    if (pTextItem == NULL)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    UINT SelectedSettingIndex = pTextItem->GetCookie();
    if (SelectedSettingIndex < 0 || SelectedSettingIndex >= ServerSettings_t::sc_ServerSettingsItems)
    {
        ASSERT(FALSE); 
        return E_UNEXPECTED; 
    }
    
    UINT statusHeader = ServerSettings_t::sc_ServerSettings[SelectedSettingIndex].NotificationId;
    STATUS_HEADER_PARAMETERS Parameters = {
                                GlobalData_t::s_ModuleInstance, 
                                statusHeader, 
                                shpDefault, 
                                0, 
                                INFINITE
                                };

    return (HRESULT)SendMessage(
        GetDlgItem(m_DialogScreen, IDC_STATUSREGION), 
        WM_STATUSHEADER_ADDSTATUSNOTIFICATION, 
        (WPARAM)sizeof(STATUS_HEADER_PARAMETERS), 
        (LPARAM)&Parameters
        ); 
}

⌨️ 快捷键说明

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