msgview.cpp

来自「WIndows mobile 5.0 pocket pc sdk sample 」· C++ 代码 · 共 564 行 · 第 1/2 页

CPP
564
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

#include "stdafx.h"
#include <cemapi.h>
#include "forms.h"
#include "msgview.h"
#include "tvconsts.h"
#include "resource.h"
#include <aygshell.h>

BOOL CMsgView::ms_fRegistered = FALSE;
extern "C" HINSTANCE g_hInst;

//*******************************************************************************************
//
// CMsgView - Constructor 
//
//*******************************************************************************************
CMsgView::CMsgView(CFormProvider* pFormProvider, CMsgForm* pForm, LPMESSAGE pMsg, LPMESSAGE pMsgBase, BOOL fCompose)
{
    // The view itself will build up the message
    if ((m_pMsg = pMsg) != NULL)
    {
        m_pMsg->AddRef();
    }

    ASSERT(pForm!= NULL);

    m_pForm = pForm;

    // Allow us to get mime details for messages later.
    m_pFormProvider = pFormProvider;
    m_pFormProvider->AddRef();

    m_hWnd     = NULL;
    m_fCompose = fCompose;

    // We may later have to prefill the form with an existing message's data.
    m_wType    = 0;

    if((m_pMsgBase = pMsgBase) != NULL)
    {
        m_pMsgBase->AddRef();
    }
}

//*******************************************************************************************
//
// ~CMsgView - Destructor 
//
//*******************************************************************************************
CMsgView::~CMsgView()
{
    // Finished building up the message.
    RELEASE_OBJ(m_pMsg);
    RELEASE_OBJ(m_pFormProvider);
    
    // If we have a base message for this view, release it now.
    RELEASE_OBJ(m_pMsgBase);
    
    if (m_hWnd != NULL)
    {
        DestroyWindow(m_hWnd);
    }
}


//*******************************************************************************************
//
// OnSendCommon
//
// Send a newly composed message.
//
//*******************************************************************************************
HRESULT CMsgView::OnSendCommon(CMsgView *pMsgView)
{
    HRESULT hr = S_OK;

    // Submit the message now. This will move it from Drafts folder to the Outbox.
    // This triggers a notification from the store to Inbox, which in turn will
    // call the loaded service provider to send the message.

    hr = m_pMsg->SubmitMessage(0);
    CHR(hr);
    
    // Everything worked ok.
    hr = S_OK;

Error:

    return hr;
}


//*******************************************************************************************
//
// CMsgView::PreTranslateMsg()
//
// This method is called by 'our' message pump before the message is translated.
//
//*******************************************************************************************
BOOL CMsgView::PreTranslateMsg(MSG* pmsg)
{
    // We don't handle anything so return FALSE to let someone else handle.
    return FALSE;
}


//*******************************************************************************************
//
// Init
//
// Initialize the MsgViewBase.
//
//*******************************************************************************************
HRESULT CMsgView::Init(MESSAGEFIELDS* pMsgFields)
{
    return S_OK;
}


//*******************************************************************************************
//
// SetMessage
//
//*******************************************************************************************
HRESULT CMsgView::SetMessage(WORD wType, LPMESSAGE pMsg)
{
    if(pMsg == NULL)
    {
        return MAPI_E_INVALID_PARAMETER;
    }

    // Type is Read, Reply, Reply All, Forward.
    m_wType = wType;

    if (pMsg)
    {
        pMsg->AddRef();
    }

    // If we have a message already loaded in the form, we're done with it now.
    if (m_pMsgBase)
    {
        m_pMsgBase->Release();

        // Now store the new message to be loaded in the form.
        m_pMsgBase = pMsg;
    }
    else
    {
        m_pMsg->Release();
        m_pMsg = pMsg;
    }

    //force a repaint
    InvalidateRect(m_hWnd, NULL, FALSE);
    UpdateWindow(m_hWnd);

    return S_OK;
}


//*******************************************************************************************
//
// Create - Create the window for the message viewing object.
//
//*******************************************************************************************
BOOL CMsgView::Create(HWND hwndForm, HWND* phwndBody)
{
    HRESULT         hr                  = S_OK;
    BOOL            fSuccess            = FALSE;
    LPSPropValue    rgprops             = NULL;
    DWORD dwStyle = WS_CHILD | WS_VISIBLE;
    RECT rc;

    // Don't need to create it here if we've already created it.
    if (m_hWnd != NULL)
    {
        // Make sure the user can see it.
        SetForegroundWindow(m_hWnd);
        return TRUE;
    }

    m_hWndForm = hwndForm;


    CBR (GetClientRect(m_hWndForm, &rc));
    
    CBR (CreateTVWindow(kszTVWndClass, kszWTVindowTitle, dwStyle, &rc, hwndForm, NULL) != NULL)
    
    *phwndBody = m_hWnd;
    fSuccess = TRUE;

Error:
    return fSuccess;
   
}


//*******************************************************************************************
//
// ShowView - Show (or hide) the window.
//
//*******************************************************************************************
HRESULT CMsgView::ShowView(ULONG ulAction)
{
    return (ShowWindow(m_hWnd, (int)ulAction) ? S_OK : E_FAIL);
}


//*******************************************************************************************
//
// WndProc - WndProc for the message viewing object.
//
//*******************************************************************************************
LRESULT CMsgView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LRESULT lRet = 0;

    
    switch (uMsg)
    {

        case WM_CREATE:
            m_hWnd = hWnd;
            break;

        case WM_COMMAND:
        {
            OnCommand(wParam, lParam);
            break;
        }

        case WM_PAINT:
        {
            HDC hDC;
            PAINTSTRUCT ps;

            hDC = BeginPaint(m_hWnd, &ps);

            OnPaint(hDC);

            EndPaint(m_hWnd, &ps);
            break;
        }

        case WM_DESTROY:
            SetWindowLong(m_hWnd, GWL_USERDATA, NULL);
            break;

        default:
            DefWindowProc(hWnd, uMsg, wParam, lParam);
            break;
    }

    return lRet;
}

void CMsgView::AddToField()
{
    HRESULT         hr          = S_OK;
    ULONG           rgProps[]   = {PR_RECIPIENT_TYPE, PR_EMAIL_ADDRESS, PR_ADDRTYPE, PR_MESSAGE_CLASS};
 
    int             cb;
 
    LPSRowSet       pRowSet     = NULL;
    LPSPropValue    pVal        = NULL;
    
    LPBYTE          pb          = NULL;
    
    // * 4 because there are 4 props
    cb  = sizeof(SRowSet) + sizeof(SPropValue) * 4; // SRowSet includes one SRow.

⌨️ 快捷键说明

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