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

📄 infoapp.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    //
    //  Show default help for only PhInfo menu screens.
    //        
    switch (m_ScreenSequence.front().Id)
    {    
        case IdDefault    :
        case IdCallLogMenu:
        case IdContactMenu:
            break;

        default:
            return FALSE;
    }
    
    PH_MESSAGE_BOX_PARAMETERS   Params = {0};
    Params.StructSize = sizeof(Params);
    Params.Flags      = VDF_TYPE_MODELESS;
    Params.IconId     = IDB_HELP;
    Params.Instance   = GlobalData_t::s_ModuleInstance;
    Params.Owner      = m_HiddenWindow;
    Params.MenuId     = IDMB_MSGBOX_HELP;
    Params.pText      = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_SCREENHELP_DEFAULT);
    Params.pTitle     = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_LABEL_HELP);

    if (! PHMessageBox(&Params))
    {
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Failed to create help message box."));
        return FALSE;
    }

    m_HelpDialog = Params.result.Dialog;
    return TRUE;
}


/*------------------------------------------------------------------------------
    InfoApp_t::AuthenticateUser
    
    Helper function which checks if the user is authenticated 
    to enter a new screen 
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::AuthenticateUser(
    BOOL* pfAlreadyAuthenticated
    )
{
    if (m_WaitingForAuth)
    {
        return E_ACCESSDENIED;
    }   

    //
    // Authenticate the user
    //
    PH_AUTHENTICATE_USER_PARAMETERS AuthParam = {0};

    AuthParam.StructSize = sizeof(AuthParam);
    AuthParam.NotificationWindow  = m_HiddenWindow;
    AuthParam.NotificationMessage = WM_INFOAPP_AUTH_COMPLETE;

    HRESULT hr = PHAuthenticateUser(
        &AuthParam
        );
    if (FAILED(hr))
    {
        RETAILMSG(1, (L"PhInfo: PHAuthenticateUser failed - cannot continue [0x%x]", hr));

        return hr;
    }

    m_WaitingForAuth = (AuthParam.Result == AuthInProgress);
    *pfAlreadyAuthenticated = (AuthParam.Result == AuthSucceeded);
    return S_OK;
}

/*------------------------------------------------------------------------------
    InfoApp_t::OnCommandLine
    
    Handle a new command line notification from a user or other application - 
    verify that the user is authenticated to enter this screen or else wait
    for auth challenge results
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::OnCommandLine(
    ScreenId id
    )
{   
    //
    // Validate the id
    //
    if (id < IdDefault || id >= IdLast)
    {
        ASSERT(FALSE);
        return E_INVALIDARG;
    }

    //
    // clear the existing sequence (navigate back to the beginning)
    //
    ClearScreenSequence();

    //
    // no need to do anything here if we are being
    // created in the background...
    //
    if (id == IdEmpty)
    {
        return S_OK;
    }
    
    BOOL AlreadyAuthenticated = FALSE;
    
    HRESULT hr = AuthenticateUser(
        &AlreadyAuthenticated
        );
    if (FAILED(hr))
    {
        return hr;
    }

    //
    // If the user is not already authenticated, wait for the auth challenge to finish
    //
    if (! AlreadyAuthenticated)
    {
        m_PendingAuthScreenId = id;
        return S_OK;
    }
    //
    // Create the new screen
    //
    return CreateNewScreen(id); 
}

/*-----------------------------------------------------------------------------
    InfoApp_t::Exit

    Exit InfoApp by uninializing exchange client, outlook app etc.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::Exit()
{
    if (! m_IsRunning)
    {
        return E_FAIL;
    }

    ClearScreenSequence();

    if (m_cpOutlookApp)
    {
        m_cpOutlookApp->Logoff();
        m_cpOutlookApp = NULL;
    }

    //make sure the exchange client is shutdown...
    if (m_cpExchangeClient)
    {
        HRESULT hr = m_cpExchangeClient->Uninitialize();        
        if (SUCCEEDED(hr))
        {
            //wait for the exchange client to shutdown...
            return S_OK;
        }
    }    

    //
    // clean up our auth request (if necessary)
    //
    if (m_WaitingForAuth)
    {
        PHCancelAuthenticationRequest(m_HiddenWindow);
        m_WaitingForAuth = false;
    }

    m_cpCallerInfoDB = NULL;
    m_cpCallLogDB    = NULL;
    PostQuitMessage(0);

    return S_OK;
}

/*-----------------------------------------------------------------------------
    InfoApp_t::ClearScreenSequence

    Clear all the PhInfo screens that are displayed in sequence.
------------------------------------------------------------------------------*/
void 
InfoApp_t::ClearScreenSequence (
    void
    )
{
    //
    //  If there are any help window open, destroy it.
    //
    DestroyHelpWindow();

    while(!m_ScreenSequence.empty())
    {
        ScreenInformation ScreenInfo = m_ScreenSequence.front();
        DestroyWindow(ScreenInfo.WindowHandle);
        m_ScreenSequence.pop_front();   
    }    
    m_ScreenSequence.clear();
}

/*-----------------------------------------------------------------------------
    InfoApp_t::AddToSpeedDial

    Add the speed dial entry to the database.
------------------------------------------------------------------------------*/
HRESULT 
InfoApp_t::AddToSpeedDial(
    PH_SPEEDDIAL_ENTRY* pSpeedDial,
    BOOL                ResetNavigation
    )
{
    if (! pSpeedDial)
    {
        ASSERT(FALSE);
        return E_POINTER;
    }

    if (pSpeedDial->StructSize != sizeof(PH_SPEEDDIAL_ENTRY))
    {
        ASSERT(FALSE);
        return E_POINTER;
    }

    CComPtr<IVoIPCallerInfoDB>      cpDatabase;
    CComPtr<IVoIPCallerInfoRecord>  cpRecord;

    ce::auto_bstr   Number = SysAllocString(pSpeedDial->pNumber);
    ce::auto_bstr   Name   = SysAllocString(pSpeedDial->pName);
    
    HRESULT hr = GetCallerInfoDB(&cpDatabase);
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to get caller info DB. hr = 0x%x", hr));
        return hr;
    }
    if (!cpDatabase)
    {
        return E_FAIL;
    }

    hr = cpDatabase->FindCallerInfoByURI(
        Number, 
        &cpRecord
        );
    if (FAILED(hr))
    {
        hr = cpDatabase->CreateRecord(&cpRecord);
        if (FAILED(hr))
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to create a record in caller info DB. hr = 0x%x", hr));   
            return hr;
        }

        hr = cpRecord->put_URI(Number);
        if (FAILED(hr))
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to write URI to the caller info record. hr = 0x%x", hr));   
        }

        hr = cpRecord->put_FriendlyName(Name);
        if (FAILED(hr))
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to write Friendly to the caller info record. hr = 0x%x", hr));   
        }
    }

    ASSERT(cpRecord);

    /// now see if the user is authenticated:
    BOOL AlreadyAuthenticated = FALSE;

    hr = AuthenticateUser(&AlreadyAuthenticated);
    if (FAILED(hr))
    {
        return hr;
    }

    if (ResetNavigation)
    {
        ClearScreenSequence();
    }
    
    if (! AlreadyAuthenticated)
    {
        cpRecord->QueryInterface(
            IID_IUnknown, 
            (void**)&m_cpPendingAuthSpeedDialRecord
            );

        m_PendingAuthScreenId = IdSpeedDialEdit;
        return S_OK;
    }
    
    hr = CreateSpeedDialEditScreen(cpRecord);
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to create speed dial edit screen. hr = 0x%x", hr));   
    }
    return hr;
}

/*------------------------------------------------------------------------------
    InfoApp_t::GoBackToPreviousScreen

    Create the previous screen from the screen sequence.    
------------------------------------------------------------------------------*/
HRESULT 
InfoApp_t::GoBackToPreviousScreen (
    void
    )
{    
    //
    //  Can not have an empty screen list when we get a CANCEL.
    //
    if(m_ScreenSequence.empty()) 
    {
        Exit();
        return S_OK;
    }    

    //
    //  If there are any help window open, destroy it.
    //
    DestroyHelpWindow();

    HWND ToDestroy = m_ScreenSequence.front().WindowHandle;
    m_ScreenSequence.pop_front();
    
    //
    //  Are we out of screens?
    //
    if (m_ScreenSequence.empty()) 
    {
        DestroyWindow(ToDestroy);
        Exit();
        return S_OK;
    }

    //
    // inform the screen it needs to refresh because it is about to be displayed
    //
    SendMessage(m_ScreenSequence.front().WindowHandle, WM_SCREEN_REFRESH, 0, 0);

    //
    //  Display the previously screen in sequence.
    //
    SetForegroundWindow (m_ScreenSequence.front().WindowHandle);    

    //
    //  Destroy the old Window.
    //
    DestroyWindow(ToDestroy);
    
    return S_OK;
}


/*------------------------------------------------------------------------------
    InfoApp_t::CreateNewScreen

    Create a new screen and append it to the sequence.    
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::CreateNewScreen (     
    ScreenId Id
    )
{ 
    //
    //  Go back if the CANCEL is selected on a menu screen.
    //
    if(Id == PHMENU_CANCELLED)     
    {   
        return GoBackToPreviousScreen ();
    }

    if (Id < IdDefault || Id >= IdLast)   
    {
        ASSERT(0);
        return E_INVALIDARG;     
    }

    //don't do anything for empty screens...
    if (Id == IdEmpty)
    {
        return S_OK;
    }

    //
    //  If there are any help window open, destroy it.
    //
    DestroyHelpWindow();

    HWND NewWindow;
    HRESULT hr;
    CallListDialog_t*           pCallList;
    SpeedDialListDialog_t*      pSpeedDialList;
    BlockedCallerListDialog_t*  pBlockedCallerList; 
    
    switch (Id)
    {    
    case IdDefault    :
    case IdCallLogMenu:
    case IdContactMenu:
        NewWindow = CreatePhoneInformationMenuScreen(Id);
        if (! NewWindow)
        {
            return CommonUtilities_t::GetErrorFromWin32();
        }
        break;          

    case IdIncomingCallsListDialog:
    case IdOutgoingCallsListDialog:
    case IdMissedCallsListDialog:
        pCallList = new CallListDialog_t(Id);
        if (pCallList == NULL)
        {
            return E_OUTOFMEMORY;
        }
        
        hr = pCallList->CreateDialogScreen();
        if (FAILED(hr))
        {
            delete pCallList;
            return hr;
        }
        NewWindow = pCallList->GetDialog();
        break;        

    case IdOutlookContactListDialog:
        {
            OutlookContactListDialog_t* pOutlookList = new OutlookContactListDialog_t();
            if (pOutlookList == NULL)
            {
                return E_OUTOFMEMORY;
            }
            
            hr = pOutlookList->CreateDialogScreen(this);
            if (FAILED(hr))
            {
                delete pOutlookList;
                return hr;
            }
            NewWindow = pOutlookList->GetDialog();
        }
        break;
        
    case IdGalContactListDialog:
        {
            GalListDialog_t* pGalList = new GalListDialog_t();
            if (pGalList == NULL)
            {
                return E_OUTOFMEMORY;
            }
            
            hr = pGalList->CreateDialogScreen();
            if (FAILED(hr))
            {
                delete pGalList;
                return hr;
            }
            NewWindow = pGalList->GetDialog();
        }
        break;        

    case IdSpeedDialList:
        pSpeedDialList = new SpeedDialListDialog_t();
        if (! pSpeedDialList)
        {
            return E_OUTOFMEMORY;
        }

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

        NewWindow = pSpeedDialList->GetDialog();
        break;

    case IdSpeedDialEdit: 
        return CreateSpeedDialEditScreen(NULL);

    case IdBlockedCallers:
        pBlockedCallerList = new BlockedCallerListDialog_t();
        if (pBlockedCallerList == NULL)
        {
            return E_OUTOFMEMORY;
        }
        
        hr = pBlockedCallerList->CreateDialogScreen();
        if (FAILED(hr))
        {
            delete pBlockedCallerList;
            return hr;
        }
        NewWindow = pBlockedCallerList->GetDialog();
        break;        
        
    default:
        ASSERT(FALSE);
        return E_INVALIDARG;
    } 

    ASSERT(NewWindow);

    return AddToScreenSequence (Id, NewWindow);
}

/*------------------------------------------------------------------------------
    InfoApp_t::CreateSpeedDialEditScreen

    Create speed dial edit screen.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::CreateSpeedDialEditScreen(
    IUnknown* pUnk
    )
{
    SpeedDialEditDialog_t* pDialog = new SpeedDialEditDialog_t();
    if (! pDialog)
    {
        return E_OUTOFMEMORY;
    }

    HRESULT hr = pDialog->CreateDialogScreen(
        pUnk, 
        this
        );
    if (FAILED(hr))
    {
        delete pDialog;
        return hr;
    }

    return AddToScreenSequence(IdSpeedDialEdit, pDialog->GetDialog());
}

/*------------------------------------------------------------------------------
    InfoApp_t::CreateDetailsScreen
    
    Create [Call/GAL/Contact]details screen.
------------------------------------------------------------------------------*/
HRESULT
InfoApp_t::CreateDetailsScreen(
    ScreenId  DetailsScreenId,
    IUnknown* pUnk
    )
{
    CallDetailsDialog_t* pDetailsScreen = new CallDetailsDialog_t(
        DetailsScreenId, 
        pUnk
        );

    HRESULT hr;
    if (!pDetailsScreen)
    {
        hr = E_OUTOFMEMORY;
        goto exit;        
    }
    

⌨️ 快捷键说明

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