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

📄 downloadlogdlg.cpp

📁 背单词程序
💻 CPP
字号:
// DownloadLogDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EngRecite.h"
#include "DownloadLogDlg.h"
#include <afxpriv.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDownloadLogDlg dialog


CDownloadLogDlg::CDownloadLogDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDownloadLogDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDownloadLogDlg)
	//}}AFX_DATA_INIT
}


void CDownloadLogDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDownloadLogDlg)
	DDX_Control(pDX, IDC_MAIL_LIST, m_lstMail);
	DDX_Control(pDX, IDC_DOWNLOAD_STATUS, m_labDownload);
	DDX_Control(pDX, IDC_DOWNLOAD_PROGRESS, m_grsDownload);
	DDX_Control(pDX, IDC_BUTTON, m_btnButton);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDownloadLogDlg, CDialog)
	//{{AFX_MSG_MAP(CDownloadLogDlg)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDownloadLogDlg message handlers

HINSTANCE			hInstMail;
LPMAPILOGON			lpfnMAPILogon;			// MAPILogon function pointer
LPMAPILOGOFF		lpfnMAPILogoff;			// MAPILogoff function pointer
LPMAPISENDMAIL		lpfnMAPISendMail;		// MAPISendMail function pointer
LPMAPIRESOLVENAME	lpfnMAPIResolveName;	// MAPIResolveName function pointer
LPMAPIREADMAIL		lpfnMAPIReadMail;
LPMAPIFINDNEXT		lpfnMAPIFindNext;
LPMAPIADDRESS		lpfnMAPIAddress;
LPMAPIFREEBUFFER	lpfnMAPIFreeBuffer;		// MAPIFreeBuffer function pointer

BOOL CDownloadLogDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	
	hInstMail = ::LoadLibrary("mapi32.DLL");
	if (hInstMail == NULL)
	{
		::AfxMessageBox(_T("Error: failed to load mapi32.dll."), MB_OK | MB_ICONERROR);
		EndDialog(IDCANCEL);
	}

	lpfnMAPILogon		= (LPMAPILOGON)			::GetProcAddress(hInstMail, "MAPILogon");
	ASSERT(lpfnMAPILogon != NULL);

	lpfnMAPILogoff		= (LPMAPILOGOFF)		::GetProcAddress(hInstMail, "MAPILogoff");
	ASSERT(lpfnMAPILogoff != NULL);

	lpfnMAPISendMail	= (LPMAPISENDMAIL)		::GetProcAddress(hInstMail, "MAPISendMail");
	lpfnMAPIResolveName	= (LPMAPIRESOLVENAME)	::GetProcAddress(hInstMail, "MAPIResolveName");
	lpfnMAPIReadMail	= (LPMAPIREADMAIL)		::GetProcAddress(hInstMail, "MAPIReadMail");
	lpfnMAPIFindNext	= (LPMAPIFINDNEXT)		::GetProcAddress(hInstMail, "MAPIFindNext");
	lpfnMAPIAddress		= (LPMAPIADDRESS)		::GetProcAddress(hInstMail, "MAPIAddress");
	lpfnMAPIFreeBuffer	= (LPMAPIFREEBUFFER)	::GetProcAddress(hInstMail, "MAPIFreeBuffer");

	SetTimer(0, 1000, NULL);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDownloadLogDlg::OnTimer(UINT nIDEvent) 
{
	CDialog::OnTimer(nIDEvent);

	if (0 == nIDEvent)
	{
		KillTimer(0);

		LHANDLE lhSession;
		ULONG lResult = lpfnMAPILogon(0, NULL, NULL, MAPI_FORCE_DOWNLOAD, 0, &lhSession);
		if (lResult != SUCCESS_SUCCESS)
		{
			MessageBox(_T("Error: failed to invoke MAPILogon function"),
							_T("System Error"),
							MB_OK | MB_ICONERROR);
			EndDialog(IDCANCEL);
			return;
		}

		m_labDownload.SetWindowText(_T("Downloading..."));

		int nCount = 0;

		while (TRUE)
		{
			char szMessageID[512 + 1];

			lResult = lpfnMAPIFindNext(lhSession, NULL, NULL, NULL, MAPI_LONG_MSGID | MAPI_UNREAD_ONLY, 0, szMessageID);
			if (lResult == MAPI_E_NO_MESSAGES)
			{
				break;
			}
			if (lResult != SUCCESS_SUCCESS)
			{
				MessageBox(_T("Error: failed to invoke MAPIFindNext function"),
								_T("System Error"),
								MB_OK | MB_ICONERROR);
				EndDialog(IDCANCEL);
				return;
			}

			lpMapiMessage pMailMessage;

			m_labDownload.SetWindowText(_T("Downloading..."));

			lResult = lpfnMAPIReadMail(lhSession, NULL, szMessageID, 0, 0, &pMailMessage);
			if (lResult != SUCCESS_SUCCESS)
			{
				MessageBox(_T("Error: failed to invoke MAPIReadMail function"),
								_T("System Error"),
								MB_OK | MB_ICONERROR);
				EndDialog(IDCANCEL);
				return;
			}

			CString msg;

			msg.Format(_T("Subject: %s\tMsg Type: %s\tDate: %s\tSize: %d\tAttach: %s"),
								pMailMessage->lpszSubject,
								pMailMessage->lpszMessageType,
								pMailMessage->lpszDateReceived,
								pMailMessage->nRecipCount,
								pMailMessage->nFileCount > 0 ? _T("TRUE") : _T("FALSE"));

			m_lstMail.AddString(msg);

			lpfnMAPIFreeBuffer(pMailMessage);
		}
		
		m_labDownload.SetWindowText(_T("Downloaded."));
	}

	if (1 == nIDEvent)
	{
	}

}

void CDownloadLogDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	if (hInstMail != NULL)
	{
		::FreeLibrary(hInstMail);
	}
}

⌨️ 快捷键说明

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