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

📄 settingsapp.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// 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 "SettingsMenu.hpp"
#include "CallForwarding.hpp"
#include "VolumeSettings.hpp"
#include "RingTonesSettings.hpp"
#include "WindowsLogon.hpp"
#include "ViewServerSettings.hpp"
#include "EditServerSettings.hpp"
#include "SetPIN.hpp"
#include "CommandAPI.hpp"
#include "ControlDefinitions.h"
#include "Resource.h"


HINSTANCE GlobalData_t::s_ModuleInstance = NULL;
GDICache_t GlobalData_t::s_GDICacheObject;

struct NameToId
{
    const WCHAR*            pName;
    SettingsApp_t::ScreenId Id;
};

SettingsApp_t::ScreenId
CommandLineToScreenId(
    const WCHAR* pCommandLine
    )
{
    if (! pCommandLine || ! pCommandLine[0])
    {
        return SettingsApp_t::IdSettings;
    }

    const NameToId  c_Map[] =
    {
        { L"CallForwarding"     , SettingsApp_t::IdCallForwarding       },
        { L"PhoneSettings"      , SettingsApp_t::IdPhoneSettings        },
        { L"UserSettings"       , SettingsApp_t::IdUserSettings         },
        { L"VolumeSettings"     , SettingsApp_t::IdVolumeSettings       },
        { L"RingTones"          , SettingsApp_t::IdRingTones            },
        { L"ServerSettings"     , SettingsApp_t::IdViewServerSettings   },
        { L"EditServerSettings" , SettingsApp_t::IdEditServerSettings   },
        { L"WindowsLogon"       , SettingsApp_t::IdWindowsLogon         },
        { L"SetPIN"             , SettingsApp_t::IdSetPIN               },
    };

    for (int i = 0; i < _countof(c_Map); i++)
    {
        if (wcsicmp(pCommandLine, c_Map[i].pName) == 0)
        {
            return c_Map[i].Id;
        }
    }  
    
    return SettingsApp_t::IdSettings;
}

SettingsApp_t::SettingsApp_t()
{
    m_IsRunning     = false;
    m_TopScreen     = NULL;
    m_TopId         = IdLast;

    m_WaitingForAuth      = false;
    m_PendingAuthScreenId = IdLast;
}

SettingsApp_t::~SettingsApp_t()
{
    ASSERT(!m_IsRunning);
}

HRESULT
SettingsApp_t::SendCommandLine(
    const WCHAR* pCommandLine
    )
{
    HWND PreviousInstanceWnd = PHGetAppWindow(phaSettingsApp, FALSE);
    if (! PreviousInstanceWnd)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    SendMessage(
        PreviousInstanceWnd, 
        WM_NEW_COMMAND_LINE,
        static_cast<WPARAM>(CommandLineToScreenId(pCommandLine)),
        0
        );
    return S_OK;
}

HRESULT
SettingsApp_t::Run(
    HINSTANCE hInstance,                      
    const WCHAR* pCommandLine
    )
{
    HRESULT hr = S_OK;

    if (m_IsRunning)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }
    
    MSG msg = {0};

    GlobalData_t::s_ModuleInstance = hInstance;

    if (! SetPINDialog_t::Register() || ! WindowsLogonDialog_t::Register())
    {
        ASSERT(FALSE);
        goto exit;
    }

    //create hidden window
    hr = CreateHiddenWindow();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        goto exit;
    }

    //indicate we are running
    m_IsRunning = true;

    hr = OnCommandLine(
        CommandLineToScreenId(pCommandLine)
        );
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        goto exit;
    }

    //pump messages
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

exit:
    m_IsRunning = false;

    //
    // If we have outstanding auth requests, cancel them
    //
    if (m_WaitingForAuth)
    {
        PHCancelAuthenticationRequest(m_HiddenWindow);
    }

    SetPINDialog_t::Unregister();
    WindowsLogonDialog_t::Unregister();
    
    DestroyHiddenWindow();
    return hr;
}

HRESULT
SettingsApp_t::CreateHiddenWindow()
{
    WNDCLASS    WndClass    = {0};
    WndClass.cbWndExtra     = sizeof(this);
    WndClass.hInstance      = GlobalData_t::s_ModuleInstance;
    WndClass.lpfnWndProc    = s_HiddenWndProc;
    WndClass.lpszClassName  = WNDCLASS_SETTINGS;

    if (! RegisterClass(&WndClass) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    m_HiddenWindow = CreateWindowEx(
        WS_EX_NOACTIVATE,
        WNDCLASS_SETTINGS, 
        NULL, 
        0, 0, 0, 0, 0, 
        NULL, NULL, 
        GlobalData_t::s_ModuleInstance, 
        reinterpret_cast<VOID*>(this)
        );
    if (! m_HiddenWindow)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    return S_OK;
}

void 
SettingsApp_t::DestroyHiddenWindow()
{
    if (m_HiddenWindow)
    {
        DestroyWindow(m_HiddenWindow);
        m_HiddenWindow = NULL;
    }

    UnregisterClass(WNDCLASS_SETTINGS, GlobalData_t::s_ModuleInstance);
    return;
}

LRESULT 
WINAPI 
SettingsApp_t::s_HiddenWndProc(
    HWND   hwndDialog, 
    UINT   uMsg, 
    WPARAM wParam,
    LPARAM lParam
    )
{
    SettingsApp_t*  pThis = NULL;
    LRESULT     Result;

    if (uMsg == WM_CREATE)
    {
        CREATESTRUCT*   pStruct = reinterpret_cast<CREATESTRUCT*>(lParam);
        if (! pStruct)
        {
            ASSERT(FALSE);
            return -1;
        }

        SetWindowLong(
            hwndDialog, 
            GWL_USERDATA, 
            reinterpret_cast<LONG>(pStruct->lpCreateParams)
            );
    }

    pThis = reinterpret_cast<SettingsApp_t*>(GetWindowLong(hwndDialog, GWL_USERDATA));
    if (! pThis)
    {
        Result = DefWindowProc(hwndDialog, uMsg, wParam, lParam);
    }
    else
    {
        Result = pThis->HiddenWndProc(hwndDialog, uMsg, wParam, lParam);
    }

    if (uMsg == WM_DESTROY)
    {
        SetWindowLong(hwndDialog, GWL_USERDATA, 0);
    }

    return Result;
}

HRESULT
SettingsApp_t::CreateNewWindow(     
    SettingsApp_t::ScreenId id
    )
{
    WindowsLogonDialog_t*       pWindowsLogonDialog;
    SetPINDialog_t*             pSetPINDialog;
    CallForwardingDialog_t*     pCallForwardingDialog;
    VolumeSettingsDialog_t*     pVolumeSettingsDialog;
    RingTonesSettingsDialog_t*  pRingTonesSettingsDialog;
    ViewServerSettingsDialog_t* pViewServerSettingsDialog;
    EditServerSettingsDialog_t* pEditServerSettingsDialog;
    
    HRESULT hr = S_OK;
    int SelectedIndex = 0;

    HWND NewWindow = NULL;
    HWND ToDestroy = NULL;
    
    //Clean Help screen
    SettingsMenu_t::CleanupHelpScreen();

    switch (id)
    {
    case SettingsApp_t::IdSettings:
    case SettingsApp_t::IdPhoneSettings:
    case SettingsApp_t::IdUserSettings:
        hr = SettingsMenu_t::CreateMenuScreen(
            m_HiddenWindow,
            id,
            &NewWindow
            );
        if (FAILED(hr))
        {
            return hr;
        }
        break;
        
    case SettingsApp_t::IdCallForwarding:
        pCallForwardingDialog = new CallForwardingDialog_t();
        if (!pCallForwardingDialog)
        {
            return E_OUTOFMEMORY;
        }

        hr = pCallForwardingDialog->CreateDialogScreen();
        if (FAILED(hr))
        {
            delete pCallForwardingDialog;
            return hr;
        }

        NewWindow = pCallForwardingDialog->GetDialog();
        break;

    case SettingsApp_t::IdVolumeSettings:
        pVolumeSettingsDialog = new VolumeSettingsDialog_t();
        if (!pVolumeSettingsDialog)
        {
            return E_OUTOFMEMORY;
        }
        hr = pVolumeSettingsDialog->CreateDialogScreen();
        if (FAILED(hr))
        {
            delete pVolumeSettingsDialog;
            return hr;

⌨️ 快捷键说明

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