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

📄 homescreen.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
void
HomeScreen_t::GetTimeText(
    ce::wstring& Buffer
    )
{
    Buffer.clear();

    GetTimeFormat(
        LOCALE_USER_DEFAULT,
        TIME_NOSECONDS,
        NULL,
        NULL,
        Buffer.get_buffer(),
        Buffer.capacity()
        );
    return;
}

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

    Determines whether the date has changed since the last update.
------------------------------------------------------------------------------*/
//inline
bool
HomeScreen_t::HasDateChanged(
    const SYSTEMTIME* pTime
    ) const
{
    return ((pTime->wDay != m_LastUpdated.wDay) ||
        (pTime->wMonth != m_LastUpdated.wMonth) ||
        (pTime->wYear != m_LastUpdated.wYear));
}

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

    Determines whether the time has changed since the last update.
------------------------------------------------------------------------------*/
//inline
bool
HomeScreen_t::HasTimeChanged(
    const SYSTEMTIME* pTime
    ) const
{
    return ((pTime->wMinute != m_LastUpdated.wMinute) ||
        (pTime->wHour != m_LastUpdated.wHour));
}

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

    Enables / disables the softkey buttons as needed (updates the menu bar).
------------------------------------------------------------------------------*/
void
HomeScreen_t::RefreshMenuButtons(
    void
    )
{
    MenuBar_t MenuBar;
    MenuBar = GetDlgItem(m_hwnd, IDC_MENUBAR);

    MENUITEMINFO Info;
    Info.cbSize = sizeof(MENUITEMINFO);
    Info.fMask = MIIM_ID | MIIM_TYPE;
    Info.fType = MFT_STRING;

    //Enable the Lock/UnLock button
    if (m_State & DEVICE_LOCKED)
    {
        Info.wID = IDM_UNLOCK;
        Info.dwTypeData = const_cast<WCHAR*>(CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            IDS_UNLOCK
            ));
    }
    else
    {
        Info.wID = IDM_LOCK;
        Info.dwTypeData = const_cast<WCHAR*>(CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            IDS_LOCK
            ));
    }
    Info.cch = Info.dwTypeData ? wcslen(Info.dwTypeData) : 0;
    MenuBar.SetMenuButtonInfo(
        m_MenuButtonMapping[ButtonLock],
        &Info
        );

    //Now update the rest of the buttons
    if ((m_RegistrationStatus & VOIP_NO_SIP_SETTINGS_BITMASK) ||
        !(m_RegistrationStatus & VOIP_REGISTERED_BITMASK))
    {
        //Enable the "Settings" button
        Info.wID = IDM_SETTINGS;
        Info.dwTypeData = const_cast<WCHAR*>(CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            IDS_SETTINGS
            ));
        Info.cch = Info.dwTypeData ? wcslen(Info.dwTypeData) : 0;
        MenuBar.SetMenuButtonInfo(m_MenuButtonMapping[ButtonSettings], &Info);
    }
    else if (m_State & (AUTOFORWARDING | DO_NOT_DISTURB))
    {
        //Enable the "Cancel" button
        Info.wID = IDCANCEL;
        Info.dwTypeData = const_cast<WCHAR*>(CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            IDS_CANCEL
            ));
        Info.cch = Info.dwTypeData ? wcslen(Info.dwTypeData) : 0;
        MenuBar.SetMenuButtonInfo(m_MenuButtonMapping[ButtonCancel], &Info);
    }
    else if (m_State & MISSED_CALLS)
    {
        //Enable the "See Missed Calls" button
        Info.wID = IDM_MISSED_CALLS;
        Info.dwTypeData = const_cast<WCHAR*>(CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance,
            IDS_MISSED_CALLS
            ));
        Info.cch = Info.dwTypeData ? wcslen(Info.dwTypeData) : 0;
        MenuBar.SetMenuButtonInfo(m_MenuButtonMapping[ButtonMissedCalls], &Info);
    }
    else
    {
        //Disable all the buttons
        MenuBar.ShowMenuButton(IDM_SETTINGS, FALSE);
        MenuBar.ShowMenuButton(IDCANCEL, FALSE);
        MenuBar.ShowMenuButton(IDM_MISSED_CALLS, FALSE);
    }

    return;
}

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

    Returns the window class name for the Home Screen.
------------------------------------------------------------------------------*/
const WCHAR*
HomeScreen_t::GetWindowClassName(
    void
    )
{
    return WNDCLASS_HOMEAPP;
}

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

    WndProc for this dialog
------------------------------------------------------------------------------*/
BOOL
HomeScreen_t::DialogWindowProc(
    UINT Message,
    WPARAM wParam,
    LPARAM lParam,
    bool& Handled
    )
{
    Handled = true;

    switch (Message)
    {
    case WM_HOMESCREEN_REGISTRYCHANGE:
        return OnRegistrySettingsChange(lParam);

    case WM_HOMESCREEN_UNLOCKREQUESTCOMPLETE:
        OnUnlockRequestComplete(
            static_cast<AuthenticationResult_e>(wParam)
            );
        return 0;

    case WM_AUTHENTICATE_USER:
        return OnAuthenticateUser(
            static_cast<UINT>(wParam),
            reinterpret_cast<HWND>(lParam)
            );

    case WM_CANCEL_AUTH_REQUEST:
        //if the unlock dialog is a window, proxy this request
        //to that dialog
        if (m_UnlockDialog.IsValid())
        {
            return SendMessage(
                m_UnlockDialog, 
                Message, 
                wParam,
                lParam
                );
        }
        return E_FAIL;
            
    case WM_CHAR:
        PHOnHookDialing(
            static_cast<WCHAR>(wParam)
            );
        return 0;

    case WM_COMMAND:
        return OnCommand(
            LOWORD(wParam),
            HIWORD(wParam),
            reinterpret_cast<HWND>(lParam)
            );

    case WM_DESTROY:
        return OnDestroy();

    case WM_ERASEBKGND:
        return OnEraseBackground(reinterpret_cast<HDC>(wParam), lParam);

    case WM_GETTEXT:
        return OnGetText(reinterpret_cast<WCHAR*>(lParam), wParam);

    case WM_GETTEXTLENGTH:
        return OnGetTextLength();

    case WM_HELP:
        return OnHelp();

    case WM_HOTKEY:
        return OnHotKey(wParam, LOWORD(lParam), HIWORD(lParam));

    case WM_INITDIALOG:
        return OnInitDialog(
            reinterpret_cast<HWND>(wParam),
            reinterpret_cast<void*>(lParam)
            );

    case WM_NOTIFY:
        return OnNotify(wParam, reinterpret_cast<NMHDR*>(lParam));

    case WM_PAINT:
        return LogoScreen_t::OnPaint(m_hwnd);

    case WM_TIMER:
        return OnTimer(
            wParam,
            reinterpret_cast<TIMERPROC*>(lParam)
            );

    case WM_HIBERNATE: 
        return OnHibernate(); 

    default:
        Handled = false;
        return 0;
    }
}

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

    Handle command messages (notifies owner)
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnCommand(
    WORD CommandId,
    WORD NotifyCode,
    HWND Control
    )
{
    switch (CommandId)
    {
    case IDM_LOCK:
        LockDevice();
        break;

    case IDM_UNLOCK:
        AuthenticateLaunch(LaunchHomescreen);
        break;

    case IDM_SETTINGS:
        AuthenticateLaunch(LaunchSettings);
        break;

    case IDCANCEL:
        AuthenticateLaunch(LaunchCancelSetting);
        break;

    case IDM_MISSED_CALLS:
        AuthenticateLaunch(LaunchMissedCalls);
        break;        

    default:
        break;
    }

    return 0;
}

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

    Unregisters hotkeys and registry change notifications
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnDestroy(
    void
    )
{
    if (m_MainTimerId)
    {
        KillTimer(m_hwnd, m_MainTimerId);
        m_MainTimerId = 0;
    }

    UnRegisterNotifications();

    HotKeys_t::UnRegisterHotKeys(m_hwnd);

    return 0;
}

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

    Handles WM_ERASEBKGND message
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnEraseBackground(
    HDC hdc,
    LPARAM lParam
    )
{
    LRESULT Result;

    Result = LogoScreen_t::OnEraseBackground(
        m_hwnd,
        IDB_LOGO_BIG,
        hdc, 
        lParam
        );

    //Draw the divider line
    //Adjust line to be right under the main text
    RECT ClientRect;
    GetClientRect(m_hwnd, &ClientRect);

    PaintHelper_t paint;
    if (SUCCEEDED(paint.Attach(hdc)))
    {
        ce::auto_hpen Pen;
        Pen = CreatePen(PS_SOLID, -1, Colors_t::HomeScreenDividerLineColor());
        paint.SetPen(Pen);

        POINT DividerLine[2];
        DividerLine[0].x = ClientRect.left;
        DividerLine[0].y = m_DividerLinePosition;
        DividerLine[1].x = ClientRect.right;
        DividerLine[1].y = DividerLine[0].y;

        Polyline(
            paint,
            DividerLine,
            _countof(DividerLine)
            );

        paint.End();
    }
    return Result;
}

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

    Returns the text displayed in the Home Screen (concatenated string)
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnGetText(
    WCHAR* pBuffer,
    int cchBuffer
    )
{
    if (!pBuffer || (cchBuffer <= 0))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }

    ce::wstring Buffer;
    Buffer.reserve(cchBuffer);

    WCHAR* pCopyLocation = pBuffer;
    size_t cchRemaining = cchBuffer;
    int i;

    for (i = 0; i < _countof(sc_MappingTextInfo); i++)
    {
        TransparentTextBox_t TextBox;
        TextBox = GetDlgItem(m_hwnd, sc_MappingTextInfo[i].m_ControlId);

        TextBox.GetText(Buffer.get_buffer(), Buffer.capacity());
        Buffer.append(L'$');

        HRESULT hr = StringCchCopyExW(
            pCopyLocation,
            cchRemaining,
            Buffer,
            &pCopyLocation,
            &cchRemaining,
            0
            );
        if (FAILED(hr))
        {
            break;
        }
    }

    return wcslen(pBuffer);
}

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

    Returns the length of buffer required to hold the Home Screen text 
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnGetTextLength(
    void
    )
{
    return MAX_PATH*2;
}

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

    Shows the default help message
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnHelp(
    void
    )
{
    CloseHelpMessage();

    //show the help message...
    PH_MESSAGE_BOX_PARAMETERS MessageBoxParams = {0};
    MessageBoxParams.StructSize = sizeof(MessageBoxParams);
    MessageBoxParams.Flags = VDF_TYPE_MODELESS;
    MessageBoxParams.Owner = m_hwnd;
    MessageBoxParams.Instance = GlobalData_t::s_ModuleInstance;
    MessageBoxParams.pTitle = MAKEINTRESOURCE(IDS_TITLE_HELP);
    MessageBoxParams.pText = MAKEINTRESOURCE(IDS_HELP_DEFAULT);
    MessageBoxParams.IconId = IDB_MESSAGEBOX;
    MessageBoxParams.MenuId = IDMB_OK;

    BOOL Success = PHMessageBox(&MessageBoxParams);
    ASSERT(Success);

    m_HelpMessageBox = MessageBoxParams.result.Dialog;

    return 0;
}

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

    Handle WM_HOTKEY notifications
------------------------------------------------------------------------------*/
LRESULT
HomeScreen_t::OnHotKey(
    UINT HotKeyId,
    short Modifiers,
    short VirtualKey
    )
{
    HotKeys_t::HotKeyId_e vkHotKey =
        static_cast<HotKeys_t::HotKeyId_e>(HotKeyId);

    if (vkHotKey >= HotKeys_t::LastHotKey)
    {
        return 0;
    }

    ASSERT(VirtualKey == HotKeys_t::GetHotKey(vkHotKey));

    bool NeedToWaitForPressAndHold = false;
    bool IsPressAndHold = false;

    if (m_State & WAITING_FOR_PRESS_AND_HOLD)
    {
        DWORD CurrentTick = GetTickCount();

        IsPressAndHold = (m_LastHotKey == HotKeyId) &&
            (CurrentTick >= m_PressAndHoldTimeout) && (
                (m_PressAndHoldTimeout >= sc_PressAndHoldTimeOut) ||
                (CurrentTick < (UINT)(m_PressAndHoldTimeout - sc_PressAndHoldTimeOut))
            );
    }

    if (Modifiers & MOD_KEYUP)
    {
        m_LastHotKey = -1;

        if (!(m_State & WAITING_FOR_PRESS_AND_HOLD))
        {
            return 0;
        }

⌨️ 快捷键说明

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