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

📄 homescreen.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
// 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 "HomeScreen.hpp"
#include <Controls.hpp>
#include <Common.hpp>
#include <VoIPNotify.hpp>
#include <HotKeys.hpp>
#include <BldVer.h>
#include <PaintHelper.hpp>
#include <MemTrace.hpp>
#include "ProcessMonitor.hpp"
#include "Layout.hpp"
#include "Resource.h"
#include <PhoneApi.hpp>
#include <Windowsx.h>
#include "CommandAPI.hpp"
#include <auto_xxx.hxx>         

HRESULT
GetMyIPAddress(
    __in_ecount(cchBuffer) WCHAR* pBuffer,
    int cchBuffer
    );

#define WM_HOMESCREEN_REGISTRYCHANGE            (WM_USER + 1)
#define WM_HOMESCREEN_UNLOCKREQUESTCOMPLETE     (WM_USER + 2)

const UINT HomeScreen_t::sc_AutoHandledNotificationTimeOut = 3000;
const UINT HomeScreen_t::sc_MainTimerTimeOut = 250;
const UINT HomeScreen_t::sc_PressAndHoldTimeOut = 1000;

const DWORD HomeScreen_t::DEVICE_LOCKED                 = 0x00000001;
const DWORD HomeScreen_t::WAITING_FOR_PRESS_AND_HOLD    = 0x00000002;
const DWORD HomeScreen_t::AUTOFORWARDING                = 0x00000004;
const DWORD HomeScreen_t::DO_NOT_DISTURB                = 0x00000008;
const DWORD HomeScreen_t::MISSED_CALLS                  = 0x00000010;


const HomeScreen_t::RegistrySetting_t HomeScreen_t::sc_RegistrySettings[] =
{
    {// RegistrationStatus
        SN_VOIP_SERVERSTATUS_ROOT,
        SN_VOIP_SERVERSTATUS_PATH,
        SN_VOIP_SERVERSTATUS_VALUE
    },
    {// AutoForwarding
        SN_VOIP_CALLFORWARDING_ROOT,
        SN_VOIP_CALLFORWARDING_PATH,
        SN_VOIP_CALLFORWARDING_VALUE
    },
    {// AutoForwardingNumber
        SN_VOIP_FORWARDINGNUMBER_ROOT,
        SN_VOIP_FORWARDINGNUMBER_PATH,
        SN_VOIP_FORWARDINGNUMBER_VALUE
    },
    {// DoNotDisturb
        SN_VOIP_DONOTDISTURB_ROOT,
        SN_VOIP_DONOTDISTURB_PATH,
        SN_VOIP_DONOTDISTURB_VALUE
    },
    {// AutoHandledCall
        SN_VOIP_AUTOHANDLEDCALLSTATE_ROOT,
        SN_VOIP_AUTOHANDLEDCALLSTATE_PATH,
        SN_VOIP_AUTOHANDLEDCALLSTATE_VALUE
    },
    {// AutoHandledCallerId
        SN_VOIP_AUTOHANDLEDCALLERID_ROOT,
        SN_VOIP_AUTOHANDLEDCALLERID_PATH,
        SN_VOIP_AUTOHANDLEDCALLERID_VALUE
    },
    {// MissedCalls
        SN_VOIP_NEWMISSEDCALLS_ROOT,
        SN_VOIP_NEWMISSEDCALLS_PATH,
        SN_VOIP_NEWMISSEDCALLS_VALUE
    },
    {// SIPAccount
        SN_VOIP_RTCUSERNAME_ROOT,
        SN_VOIP_RTCUSERNAME_PATH,
        SN_VOIP_RTCUSERNAME_VALUE
    },
    {// SIPAccountURI
        SN_VOIP_LOCALURI_ROOT,
        SN_VOIP_LOCALURI_PATH,
        SN_VOIP_LOCALURI_VALUE
    },
    {// LoginUserName
        SN_VOIP_LOGINUSERNAME_ROOT,
        SN_VOIP_LOGINUSERNAME_PATH,
        SN_VOIP_LOGINUSERNAME_VALUE,
    },
    { //Device is locked
        SN_VOIP_ISLOCKED_ROOT,
        SN_VOIP_ISLOCKED_PATH,    
        SN_VOIP_ISLOCKED_VALUE,
    },
};

const HomeScreen_t::TextInfo_t HomeScreen_t::sc_MappingTextInfo[] =
{
    { IDC_TEXT_ACCOUNT_NAME,    phfLargeText },
    { IDC_TEXT_SIP_ACCOUNT_URI, phfStandardText },
    { IDC_TEXT_DATE,            phfStandardText },
    { IDC_TEXT_TIME,            phfStandardText },
    { IDC_TEXT_INFORMATIONAL1,  phfInformationText },
    { IDC_TEXT_INFORMATIONAL2,  phfInformationText },
};


/*------------------------------------------------------------------------------
    HomeScreen_t::HomeScreen_t

    Constructor
------------------------------------------------------------------------------*/
HomeScreen_t::HomeScreen_t()
{
    m_hwnd = NULL;
    m_State = 0;

    m_AutoHandledTimerId = 0;
    m_MainTimerId = 0;
    memset(&m_LastUpdated, -1, sizeof(m_LastUpdated));

    m_LastHotKey = -1;

    memset(&m_MenuButtonMapping, -1, sizeof(m_MenuButtonMapping));

    memset(&m_Notifications, 0, sizeof(m_Notifications));
    m_RegistrationStatus = 0;
    m_AutoHandledCallState = 0;

    m_DividerLinePosition = 0;
    m_HelpMessageBox = NULL;

    m_CurrentAuthRequest = LaunchInvalid;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::~HomeScreen_t

    Destructor
------------------------------------------------------------------------------*/
HomeScreen_t::~HomeScreen_t()
{
}

/*------------------------------------------------------------------------------
    HomeScreen_t::Initialize

    Initialize the home screen object
------------------------------------------------------------------------------*/
HRESULT
HomeScreen_t::Initialize(
    )
{
    if (!PHInitCommonControls())
    {
        return CommonUtilities_t::GetErrorFromWin32();
    }

    HRESULT hr;

    // Initialize RC data
    hr = Colors_t::InitializeRCData();
    if (FAILED(hr))
    {
        ASSERT(0);
        return hr;
    }

    if (!Register())
    {
        return CommonUtilities_t::GetErrorFromWin32();
    }

    if (! EnterPinDialog_t::Register())
    {
        return CommonUtilities_t::GetErrorFromWin32();
    }
    
    HWND Dialog;
    hr = Create(
        MAKEINTRESOURCE(IDD_HOME_SCREEN),
        NULL,
        dtModelessDialog,
        NULL,
        &Dialog
        );
    ASSERT(m_hwnd == Dialog);

    return hr;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::UnInitialize

    UnInitialize the home screen object
------------------------------------------------------------------------------*/
HRESULT
HomeScreen_t::UnInitialize(
    )
{
    if (m_AutoHandledTimerId)
    {
        KillTimer(m_hwnd, m_AutoHandledTimerId);
        m_AutoHandledTimerId = 0;
    }

    if (m_MainTimerId)
    {
        KillTimer(m_hwnd, m_MainTimerId);
        m_MainTimerId = 0;
    }

    if (m_hwnd)
    {
        End();
    }

    if (IsWindow(m_UnlockDialog))
    {
        m_UnlockDialog.End();
    }

    EnterPinDialog_t::Unregister();
    Unregister();

    CloseHelpMessage();

    PHUnInitCommonControls();

    return S_OK;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::CloseHelpMessage

    Closes the help message box
------------------------------------------------------------------------------*/
void
HomeScreen_t::CloseHelpMessage(
    void
    )
{
    if (m_HelpMessageBox)
    {
        DestroyWindow(m_HelpMessageBox);
        m_HelpMessageBox = NULL;
    }
}

/*------------------------------------------------------------------------------
    HomeScreen_t::GetAutoHandledCallText

    Gets the AutoHandled Call text if available, otherwise retrieves the
    AutoForwarding or DoNotDisturb string if the user setting is enabled.
------------------------------------------------------------------------------*/
void
HomeScreen_t::GetAutoHandledCallText(
    ce::wstring& Buffer
    )
{
    Buffer.clear();

    if (m_AutoHandledCallState == 0)
    {
        if (m_State & AUTOFORWARDING)
        {
            PREFAST_SUPPRESS(5428, "It is safe to use StringCchPrintfW (known parameters)");
            StringCchPrintfW(
                Buffer.get_buffer(),
                Buffer.capacity(),
                CommonUtilities_t::LoadString(
                    GlobalData_t::s_ModuleInstance,
                    IDS_STATUS_AUTOFORWARDING_TO
                    ),
                (const WCHAR*)m_AutoForwardingNumber.get_buffer()
                );
        }
        else if (m_State & DO_NOT_DISTURB)
        {
                StringCchCopyW(
                    Buffer.get_buffer(),
                    Buffer.capacity(),
                    CommonUtilities_t::LoadString(
                        GlobalData_t::s_ModuleInstance,
                        IDS_STATUS_DO_NOT_DISTURB
                        )
                    );
        }
        return;
    }

    UINT StringId;

    if (m_AutoHandledCallState & VOIP_AUTO_BLOCKED_BITMASK)
    {
        StringId = IDS_STATUS_CALL_BLOCKED;
    }
    else if (m_AutoHandledCallState & VOIP_AUTO_FORWARDED_BYDND_BITMASK)
    {
        StringId = IDS_STATUS_CALL_MISSED;
    }
    else if (m_AutoHandledCallState & VOIP_AUTO_FORWARDED_BITMASK)
    {
        StringId = IDS_STATUS_CALL_FORWARDED;
    }
    else
    {
        ASSERT(0);
        return;
    }

    PREFAST_SUPPRESS(5428, "It is safe to use StringCchPrintfW (known parameters)");
    StringCchPrintfW(
        Buffer.get_buffer(),
        Buffer.capacity(),
        CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            StringId
            ),
        (const WCHAR*)m_AutoHandledCallerId.get_buffer()
        );

    return;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::GetDateText

    Gets the Date text using the long format specified in the registry.
------------------------------------------------------------------------------*/
void
HomeScreen_t::GetDateText(
    ce::wstring& Buffer
    )
{
    Buffer.clear();

    GetDateFormat(
        LOCALE_USER_DEFAULT,
        NULL,
        NULL,
        CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            IDS_DATE_FORMAT_LONG
            ),
        Buffer.get_buffer(),
        Buffer.capacity()
        );
    return;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::GetMainText

    Gets the Main text. The priority order is as described below
    - SIP Account or,
    - SIP URI or,
    - Default label
------------------------------------------------------------------------------*/
void
HomeScreen_t::GetMainText(
    ce::wstring& Buffer
    )
{
    if (!m_LoginUserName.empty())
    {
        Buffer = m_LoginUserName;
    }
    else if (!m_SIPAccount.empty())
    {
        Buffer = m_SIPAccount;
    }
    else if (!m_SIPAccountURI.empty())
    {
        Buffer = m_SIPAccountURI;

        int Pos = Buffer.find(L":");
        if (Pos != ce::wstring::npos)
        {
            Buffer.erase(0, ++Pos);
        }
        Buffer.erase(Buffer.find(L"@"));
    }
    else
    {
        //default
        Buffer.assign(
            CommonUtilities_t::LoadString(
                GlobalData_t::s_ModuleInstance,
                IDS_LABEL_DEFAULT_NAME
                )
            );
    }
    return;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::GetStatusText

    Gets the registration status with the server.
    An empty string is returned if succesfully registered with the server
------------------------------------------------------------------------------*/
void
HomeScreen_t::GetStatusText(
    ce::wstring& Buffer
    )
{
    if (m_RegistrationStatus & VOIP_REGISTRATION_ERROR_BITMASK)
    {
        WCHAR ErrorString[MAX_PATH] = L""; 
        RegistryGetString(
            SN_VOIP_REGISTRATIONERROR_ROOT, 
            SN_VOIP_REGISTRATIONERROR_PATH, 
            SN_VOIP_REGISTRATIONERROR_VALUE, 
            ErrorString, 
            _countof(ErrorString)
            ); 

        StringCchPrintf(
            Buffer.get_buffer(), 
            Buffer.capacity(), 
            CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_STATUS_REGISTRATION_ERROR), 
            ErrorString
            ); 

        return;         
    }

    UINT StatusId;

    if (m_RegistrationStatus & VOIP_NO_SIP_SETTINGS_BITMASK)
    {
        StatusId = IDS_STATUS_PROVISIONING_ERROR;
    }
    else if (m_RegistrationStatus & VOIP_REGISTERING_BITMASK)
    {
        StatusId = IDS_STATUS_REGISTERING;
    }
    else
    {
        Buffer.clear();
        return;
    }

    StringCchCopyW(
        Buffer.get_buffer(),
        Buffer.capacity(),
        CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            StatusId
            )
        );
    return;
}


/*------------------------------------------------------------------------------
    HomeScreen_t::GetSubText

    Gets the Sub text. The priority order is as described below
    - SIP URI or,
    - IP Address
------------------------------------------------------------------------------*/
void
HomeScreen_t::GetSubText(
    ce::wstring& Buffer
    )
{
    if (!m_SIPAccountURI.empty())
    {
        Buffer = m_SIPAccountURI;

        int Pos = Buffer.find(L":");
        if (Pos != ce::wstring::npos)
        {
            Buffer.erase(0, ++Pos);
        }
        Buffer.erase(Buffer.find(L"@"));
    }
    else
    {
        //default
        GetMyIPAddress(Buffer.get_buffer(), Buffer.capacity());
    }
    return;
}

/*------------------------------------------------------------------------------
    HomeScreen_t::GetTimeText

    Gets the Time text using TIME_NOSECONDS format for LOCALE_USER_DEFAULT 
------------------------------------------------------------------------------*/

⌨️ 快捷键说明

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