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

📄 enterpin.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 "EnterPin.hpp"
#include "resource.h"
#include "Layout.hpp"
#include <RegExt.h>
#include "VoIPNotify.hpp"
#include "Resource.h"
#include "HomeScreen.hpp"
#include <windowsx.h>

// Purpose: Set the notification parameters for this window
// WPARAM: UINT - Notification message
// LPARAM: HWND - Notification window
// Returns: HRESULT indicating success or failure
#define WM_ENTERPIN_SETNOTIFICATION_PARAMS  (WM_USER)

/*------------------------------------------------------------------------------
    EnterPinDialog_t::IsValid
    
    Determine if a window is actually a valid instance of a EnterPinDialog_t
    object
------------------------------------------------------------------------------*/
BOOL
EnterPinDialog_t::IsValid(
    void
    )
{
    WCHAR ClassName[100] = L"";

    if (! IsWindow(m_hwnd))
    {
        goto error;
    }

    if (! GetClassName(m_hwnd, ClassName, _countof(ClassName)))
    {
        ASSERT(FALSE);
        goto error;
    }

    if (wcscmp(ClassName, WNDCLASS_ENTERPIN) != 0)
    {
        ASSERT(FALSE);

        //reused handle!!!
        goto error;
    }
    
    return TRUE;

error:
    m_hwnd = NULL;
    return FALSE;
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::EnterPinDialog_t
    
    Ctor
------------------------------------------------------------------------------*/
EnterPinDialog_t::EnterPinDialog_t()
{
    m_MessageBox          = NULL;
    m_NotificationWindow  = NULL;
    m_NotificationMessage = 0;
    m_NotifiedOwner       = false;
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::~EnterPinDialog_t
    
    Dtor
------------------------------------------------------------------------------*/
EnterPinDialog_t::~EnterPinDialog_t()
{
    CloseMessageBox();

    if (! m_NotifiedOwner && IsWindow(m_NotificationWindow))
    {
        SendMessage(
            m_NotificationWindow,
            m_NotificationMessage,
            static_cast<WPARAM>(AuthCanceled),
            0
            );
    }
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::GetWindowClassName
    
    Implementation necessary for DialogControl_t user's 
------------------------------------------------------------------------------*/
const WCHAR*
EnterPinDialog_t::GetWindowClassName(
    void
    )
{
    return WNDCLASS_ENTERPIN;
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::Start
    
    Create the dialog and present it to the user
    
    Returns (HRESULT): 
------------------------------------------------------------------------------*/
HRESULT 
EnterPinDialog_t::Start(
    UINT    NotificationMessage,
    HWND    NotificationWindow
    )
{ 
    HWND Dialog;

    HRESULT hr = Create(
        MAKEINTRESOURCE(IDD_ENTER_PIN),
        NULL,
        dtModelessDialog,
        NULL,
        &Dialog
        );
    if (FAILED(hr))
    {
        return hr;
    }

    hr = SetNotificationParameters(
        NotificationMessage, 
        NotificationWindow
        );
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        End();
        return hr;
    }
    
    ASSERT(m_hwnd == Dialog);
    SetForegroundWindow(m_hwnd);
    
    return S_OK;
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::SetNotificationParameters
    
    Update our internal notification parameters
------------------------------------------------------------------------------*/
HRESULT
EnterPinDialog_t::SetNotificationParameters(
    UINT NotificationMessage, 
    HWND NotificationWindow
    )
{
    if (! IsWindow(m_hwnd))
    {
        ASSERT(FALSE);
        return E_HANDLE;
    }
    
    return (HRESULT)SendMessage(
        m_hwnd, 
        WM_ENTERPIN_SETNOTIFICATION_PARAMS,
        static_cast<WPARAM>(NotificationMessage),
        reinterpret_cast<LPARAM>(NotificationWindow)
        );
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::DialogWindowProc
    
    Standard dialog proc...
------------------------------------------------------------------------------*/
BOOL 
EnterPinDialog_t::DialogWindowProc(
    UINT    Message,
    WPARAM  wParam,
    LPARAM  lParam,
    bool&   Handled
    )
{
    Handled = true;
    switch (Message)
    {
    case WM_ACTIVATE:
        if (wParam != WA_INACTIVE)
        {
            OnEditUpdate();
        }
        return FALSE;
            
    case WM_INITDIALOG:
        if (FAILED(OnInitDialog()))
        {
            End();
        }
        return FALSE;

    case WM_ENTERPIN_SETNOTIFICATION_PARAMS:
        return OnSetNotificationParameters(
            static_cast<UINT>(wParam), 
            reinterpret_cast<HWND>(lParam)
            );

    case WM_CANCEL_AUTH_REQUEST:
        return OnCancelAuthRequest(
            reinterpret_cast<HWND>(lParam)
            );
        
    case WM_ERASEBKGND:
        return LogoScreen_t::OnEraseBackground(
            m_hwnd,
            IDB_LOGO_BIG,
            reinterpret_cast<HDC>(wParam), 
            lParam
            );

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

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

    case WM_HELP:
        //show the help message...
        ShowMessageBox(IDS_TITLE_HELP, IDS_HELP_DEFAULT);
        return TRUE;

    case WM_NOTIFY:
        switch(wParam)
        {
        case IDOK:
            CloseMessageBox();
            SetFocus(m_EditControls[0]);
            break;
        }
        return TRUE;

    default:
        Handled = false;
        return FALSE;
    }
}

/*------------------------------------------------------------------------------
    EnterPinDialog_t::OnInitDialog
    
    Handle WM_INITDIALOG
------------------------------------------------------------------------------*/
HRESULT
EnterPinDialog_t::OnInitDialog()
{
    HWND Control;

    int             Index = 0;
    HRESULT         hr    = S_OK;

    //get each edit control...
    while (1)
    {
        Control = GetDlgItem(m_hwnd, IDC_PINEDIT1 + Index);
        if (! Control)
        {
            //no more controls
            break;
        }

        //limit the control to 1 character of input
        SendMessage(Control, EM_SETLIMITTEXT, 1, 0);

        //assert that this control is a password control...
        ASSERT(GetWindowStyle(Control) & ES_PASSWORD);
        
        if (! m_EditControls.push_back(Control))
        {
            return E_OUTOFMEMORY;
        }

        Index++;
    }

    //make sure we have controls...
    if (m_EditControls.empty())
    {
        ASSERT(! L"No edit controls starting with IDC_PINEDIT1 in EnterPinDialog! - Failing creation");
        return E_FAIL;
    }

    if (! m_CurrentPin.reserve(m_EditControls.size() + 1))
    {
        return E_OUTOFMEMORY;

⌨️ 快捷键说明

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