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

📄 infoapp.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// 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 "InfoApp.hpp"
#include "ControlDefinitions.h"
#include "Resource.h"
#include "CallListDialog.hpp"
#include "CallDetailsDialog.hpp"
#include "GalListDialog.hpp"
#include "Common.hpp"
#include "SpeedDialListDialog.hpp"
#include "DatabaseAPI.hpp"
#include "SpeedDialEditDialog.hpp"
#include "Layout.hpp"
#include "BlockedCallerListDialog.hpp"
#include "OutlookContactList.hpp"
#include "VoIPNotify.hpp"

#include <wininet.h>
#include <urlmon.h>
#include "CommandAPI.hpp"

//
//  Set module name for logging.
//
MODULE_NAME (L"[PHInfo]");

DBGPARAM dpCurSettings =
{
    //Module name
    L"PHInfo",

    //Debug zone names
    {
      L"Error",                     // 1
      L"Constructor/Destructor",    // 2   Lowest Hex Digit
      L"Warning",                   // 4
      L"Information",               // 8

      L"", L"", L"", L"",           // 2nd Hex digit
      L"", L"", L"", L"",           // 3rd Hex digit
      L"", L"", L"", L"",           // 4th Hex digit
    },

    //Initial debug zone mask
    0x000d
};

//forward declaration
HRESULT Delay_UrlMkSetSessionOption(
    DWORD dwOption, 
    LPVOID pBuffer, 
    DWORD dwBufferLength, 
    DWORD dwReserved
    );

HRESULT Delay_InternetSetOption(
    HINTERNET hInternet, 
    DWORD dwOption, 
    LPVOID lpBuffer, 
    DWORD dwBufferLength
    );

const PHMS_ITEM MainMenuItems[] =
{
    { InfoApp_t::IdSpeedDialList,   IDS_TITLE_SPEEDDIAL         },
    { InfoApp_t::IdCallLogMenu  ,   IDS_TITLE_CALLLOGS          },
    { InfoApp_t::IdContactMenu  ,   IDS_TITLE_CONTACTS          },
    { InfoApp_t::IdBlockedCallers,  IDS_TITLE_BLOCKEDCALLERS    }, 
};

const PHMS_ITEM CallLogMenuItems[] =
{
    { InfoApp_t::IdIncomingCallsListDialog, IDS_TITLE_INCOMING },
    { InfoApp_t::IdOutgoingCallsListDialog, IDS_TITLE_OUTGOING },
    { InfoApp_t::IdMissedCallsListDialog,   IDS_TITLE_MISSED   },
};

const PHMS_ITEM ContactsMenuItems[] =
{
    { InfoApp_t::IdOutlookContactListDialog, IDS_TITLE_OUTLOOKCONTACTS },
    { InfoApp_t::IdGalContactListDialog,     IDS_TITLE_GAL             },
};

/*------------------------------------------------------------------------------
    InfoApp_t::CommandLineToScreenId
    
    Helper function to convert command line string to ScreenId.
------------------------------------------------------------------------------*/
InfoApp_t::ScreenId
CommandLineToScreenId(
    const WCHAR* pCommandLine
    )
{
    if (! pCommandLine || ! pCommandLine[0])
    {
        return InfoApp_t::IdDefault;
    }

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

    const NameToId  c_Map[] =
    {
        { L"speeddial"     , InfoApp_t::IdSpeedDialList            },
        { L"newspeeddial"  , InfoApp_t::IdSpeedDialEdit            },
        { L"-n"            , InfoApp_t::IdEmpty                    },
        { L"calllogs"      , InfoApp_t::IdCallLogMenu              },
        { L"incoming"      , InfoApp_t::IdIncomingCallsListDialog  },
        { L"outgoing"      , InfoApp_t::IdOutgoingCallsListDialog  },
        { L"missed"        , InfoApp_t::IdMissedCallsListDialog    },
        { L"contacts"      , InfoApp_t::IdContactMenu              },
        { L"exchange"      , InfoApp_t::IdOutlookContactListDialog },
        { L"gal"           , InfoApp_t::IdGalContactListDialog     },
        { L"blockedcallers", InfoApp_t::IdBlockedCallers           }, 
    };
    
    for (int i = 0; i < _countof(c_Map); i++)
    {
        if (wcsicmp(pCommandLine, c_Map[i].pName) == 0)
        {
            return c_Map[i].Id;
        }
    }

    return InfoApp_t::IdDefault;
}

#define WM_INFOAPP_AUTH_COMPLETE (WM_APP)

/*------------------------------------------------------------------------------
    InfoApp_t::InfoApp_t
    
    Constructor
------------------------------------------------------------------------------*/
InfoApp_t::InfoApp_t()
{
    m_IsRunning    = false;
    m_HiddenWindow = NULL;
    m_NotifyHandle = NULL;
    m_HelpDialog   = NULL;
    m_RefCount     = 1;

    m_WaitingForAuth      = false;
    m_PendingAuthScreenId = IdDefault;
}

/*------------------------------------------------------------------------------
    InfoApp_t::~InfoApp_t
    
    Destructor
------------------------------------------------------------------------------*/
InfoApp_t::~InfoApp_t()
{
    ASSERT(!m_IsRunning);
}

/*------------------------------------------------------------------------------
    InfoApp_t::AddRef
    
    Standard non-thread-safe add-ref...
------------------------------------------------------------------------------*/
ULONG STDMETHODCALLTYPE InfoApp_t::AddRef()
{
    m_RefCount++;
    return m_RefCount;
}

/*------------------------------------------------------------------------------
    InfoApp_t::Release
    
    Non-destructing release
------------------------------------------------------------------------------*/
ULONG STDMETHODCALLTYPE InfoApp_t::Release()
{
    //not a real com object...
    m_RefCount--;
    ASSERT(m_RefCount > 0);

    return m_RefCount;
}

/*------------------------------------------------------------------------------
    InfoApp_t::QueryInterface
    
    Standard query interface...
------------------------------------------------------------------------------*/
HRESULT STDMETHODCALLTYPE InfoApp_t::QueryInterface(
    REFIID riid,
    VOID** ppvObj
    )
{
    if (! ppvObj)
    {
        ASSERT(FALSE);
        return E_POINTER;
    }

    HRESULT hr = S_OK;
    
    if (riid == IID_IUnknown)
    {
        (*ppvObj) = static_cast<IUnknown*>(this);
        AddRef();
    }
    else if (riid == IID_IExchangeClientRequestCallback)
    {
        (*ppvObj) = static_cast<IExchangeClientRequestCallback*>(this);
        AddRef();
    }
    else
    {
        *ppvObj = NULL;
        hr = E_NOINTERFACE;
    }

    return hr;
}

/*------------------------------------------------------------------------------
    InfoApp_t::SendCommandLine    
    
    Send message WM_NEW_COMMAND_LINE to the message loop with the command line.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::s_SendCommandLine(
    const WCHAR* pCommandLine
    )
{
    HWND PreviousInstanceWnd = PHGetAppWindow(phaContactsApp, FALSE);
    if (!PreviousInstanceWnd)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

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

/*------------------------------------------------------------------------------
    InfoApp_t::Run    
    
    Start PhInfo application and wait for messages.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::Run(
    const WCHAR* pCommandLine
    )
{
    if (m_IsRunning)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }        
    
    //
    //  create hidden window
    //
    HRESULT hr;
    
    hr = Layout_t::InitializeRCData();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to initialize Layout RC data. hr=0x%x", hr));
        return hr;
    }
    
    hr = Colors_t::InitializeRCData();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to initialize Colors RC data. hr=0x%x", hr));
        return hr;
    }
    
    hr = CreateHiddenWindow();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to create hidden window. hr=0x%x", hr));
        return hr;
    }

    hr = ListenForSettingsChanges();
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to create listner for settings changes. hr=0x%x", hr));
        return hr;
    }

    MSG msg = {0};
    
    //
    //indicate we are running
    //
    m_IsRunning = true;

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

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

exit:
    m_IsRunning = false;

    //unregister for notifications
    if (m_NotifyHandle)
    {
        RegistryCloseNotification(m_NotifyHandle);
        m_NotifyHandle = NULL;
    }

    DestroyHiddenWindow();
    return hr;
}

/*------------------------------------------------------------------------------
    InfoApp_t::CreateHiddenWindow    
    
    Create hidden window for messaging.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::CreateHiddenWindow()
{
    WNDCLASS    WndClass   = {0};
    WndClass.cbWndExtra    = sizeof(this);
    WndClass.hInstance     = GlobalData_t::s_ModuleInstance;
    WndClass.lpfnWndProc   = s_HiddenWndProc;
    WndClass.lpszClassName = WNDCLASS_INFOAPP;

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

    m_HiddenWindow = CreateWindowEx(
            WS_EX_NOACTIVATE,
            WNDCLASS_INFOAPP, 
            NULL, 
            0, 0, 0, 0, 0, 
            NULL, NULL, 
            GlobalData_t::s_ModuleInstance, 
            reinterpret_cast<VOID*>(this)
            );
    if (!m_HiddenWindow)
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to create hidden window."));
        return E_FAIL;
    }

    return S_OK;
}

/*------------------------------------------------------------------------------
    InfoApp_t::DestroyHiddenWindow   
    
    Destroy hidden window.
------------------------------------------------------------------------------*/
void
InfoApp_t::DestroyHiddenWindow()
{
    if (m_HiddenWindow)
    {
        DestroyWindow(m_HiddenWindow);
        m_HiddenWindow = NULL;
    }

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

LRESULT 
WINAPI 
InfoApp_t::s_HiddenWndProc(
    HWND    Window,
    UINT    Message, 
    WPARAM  wParam,
    LPARAM  lParam
    )
{
    InfoApp_t*  pApp = NULL;
    LRESULT     Result;
    
    if (Message == WM_CREATE)
    {
        CREATESTRUCT*   pStruct = reinterpret_cast<CREATESTRUCT*>(lParam);
        if (! pStruct)
        {
            ASSERT(FALSE);
            return -1;
        }

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

    pApp = reinterpret_cast<InfoApp_t*>(GetWindowLong(Window, GWL_USERDATA));
    if (! pApp)
    {
        Result = DefWindowProc(Window, Message, wParam, lParam);
    }
    else
    {
        Result = pApp->HiddenWndProc(Window, Message, wParam, lParam);
    }

    if (Message == WM_DESTROY)
    {
        SetWindowLong(Window, GWL_USERDATA, 0);
    }

    return Result;
}

LRESULT 
InfoApp_t::HiddenWndProc(
    HWND    Window,
    UINT    Message, 
    WPARAM  wParam,
    LPARAM  lParam
    )
{
    if (Window != m_HiddenWindow || !m_IsRunning)
    {
        goto exit;
    }

    switch (Message)
    {
    case WM_CLOSE:
    case WM_HIBERNATE:
        return Exit();

    case WM_HELP:
        return OnHelp();
        
    case WM_NEW_COMMAND_LINE:
        return OnCommandLine(
            (lParam) ?
                CommandLineToScreenId(reinterpret_cast<const WCHAR*>(lParam)) :
                static_cast<ScreenId>(wParam)
            );

    case WM_MENU_DONE:
        return CreateNewScreen(
            static_cast<ScreenId>(wParam)
            );

    case WM_INFOAPP_SETTINGSCHANGE:
        return OnSettingsChange(
            static_cast<DWORD>(wParam)
            );

    case WM_INFOAPP_AUTH_COMPLETE:
        return OnAuthRequestComplete(
            static_cast<AuthenticationResult_e>(wParam)
            );
        
    case WM_COPYDATA:
        {
            COPYDATASTRUCT* pCopyDataStruct = reinterpret_cast<COPYDATASTRUCT*>(lParam);
            if (! pCopyDataStruct)
            {
                return E_FAIL;
            }

            switch(pCopyDataStruct->dwData)
            {
            case INFOAPPMSG_ADDTOSPEEDDIAL:
                if (pCopyDataStruct->cbData < sizeof(PH_SPEEDDIAL_ENTRY))
                {
                    ASSERT(FALSE);
                    return E_INVALIDARG;
                }

                return AddToSpeedDial(
                    reinterpret_cast<PH_SPEEDDIAL_ENTRY*>(pCopyDataStruct->lpData),
                    TRUE //reset the navigation hierarchy
                    );

            default:
                return S_FALSE;
            }
        }
        break;

    case WM_NOTIFY:
        if(wParam == IDC_HELPMSG_OK)
        {
            DestroyHelpWindow();
        }
        break;
       
    default:
        break;
    }
exit:
    return DefWindowProc(Window, Message, wParam, lParam);
}

/*------------------------------------------------------------------------------
    InfoApp_t::DestroyHelpWindow
    
    Destroys the help window if one is present.
------------------------------------------------------------------------------*/
void 
InfoApp_t::DestroyHelpWindow (
    void
    )
{
    if (m_HelpDialog == NULL)
    {
        return;
    }
    
    DestroyWindow(m_HelpDialog);
    m_HelpDialog = NULL;
    return;
}

/*------------------------------------------------------------------------------
    InfoApp_t::OnHelp
    
    Handle WM_HELP and show default help 
------------------------------------------------------------------------------*/
BOOL
InfoApp_t::OnHelp (
    void
    )
{
    if (IsWindow(m_HelpDialog))
    {
        return TRUE;
    }

⌨️ 快捷键说明

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