SendEmailView.cpp
上传用户:jpdph_love
上传日期:2013-04-11
资源大小:116k
文件大小:3k
- // SendEmailView.cpp : implementation of the CSendEmailView class
- //
- #include "stdafx.h"
- #include "SendEmail.h"
- #include "SendEmailDoc.h"
- #include "SendEmailView.h"
- #include "Email.h"
- #include "EmailParams.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSendEmailView
- IMPLEMENT_DYNCREATE(CSendEmailView, CView)
- BEGIN_MESSAGE_MAP(CSendEmailView, CView)
- //{{AFX_MSG_MAP(CSendEmailView)
- ON_COMMAND(ID_EMAIL_SENDEMAIL, OnEmailSendemail)
- ON_WM_CREATE()
- ON_WM_TIMER()
- ON_UPDATE_COMMAND_UI(ID_EMAIL_SENDEMAIL, OnUpdateEmailSendemail)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSendEmailView construction/destruction
- CSendEmailView::CSendEmailView()
- {
- m_pEmail = NULL;
- }
- CSendEmailView::~CSendEmailView()
- {
- if( m_pEmail != NULL )
- delete m_pEmail;
- }
- BOOL CSendEmailView::PreCreateWindow(CREATESTRUCT& cs)
- {
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSendEmailView drawing
- void CSendEmailView::OnDraw(CDC* pDC)
- {
- CSendEmailDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSendEmailView diagnostics
- #ifdef _DEBUG
- void CSendEmailView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CSendEmailView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CSendEmailDoc* CSendEmailView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSendEmailDoc)));
- return (CSendEmailDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CSendEmailView message handlers
- void CSendEmailView::OnEmailSendemail()
- {
- CEmailParams Params;
-
- if( Params.DoModal() == IDOK ){
- m_pEmail = new CEmail();
- if( m_pEmail != NULL )
- m_pEmail->Send( Params.m_strAddr,
- Params.m_strMessage, Params.m_strFrom,
- Params.m_strServer, Params.m_strSubject );
- }
- }
- int CSendEmailView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // Kick off the timer.
- SetTimer( 1, 500, NULL );
-
- return 0;
- }
- void CSendEmailView::OnTimer(UINT nIDEvent)
- {
- if( m_pEmail != NULL &&
- m_pEmail->m_Info.bCompleted ){
- Sleep( 250 );
- DWORD dwLastError =
- m_pEmail->m_Info.dwLastError;
- delete m_pEmail;
- m_pEmail = NULL;
- if( dwLastError == 0 )
- AfxMessageBox( "You email was sent." );
- else
- AfxMessageBox( "There was an error." );
- }
-
- CView::OnTimer(nIDEvent);
- }
- void CSendEmailView::OnUpdateEmailSendemail(CCmdUI* pCmdUI)
- {
- // Only enable the sending of email if
- // the email class is NULL.
- pCmdUI->Enable( m_pEmail == NULL );
- }