www.pudn.com > MiniFox.rar > Wizard.cpp


// Wizard.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "MiniFox.h" 
#include "Wizard.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CWizard dialog 
 
 
CWizard::CWizard(CWnd* pParent /*=NULL*/) 
: CDialog(CWizard::IDD, pParent) 
{ 
	m_nCurPage	= 0; 
	m_nPageCount	= 0; 
	m_pPageLink		= 0; 
 
	accInfo.m_bHotmail	= 0; 
	accInfo.m_strAccName	= _T( "" ); 
	accInfo.m_strEmlAddr	= _T( "" ); 
	accInfo.m_strMailPath	= _T( "" ); 
	accInfo.m_strPassword	= _T( "" ); 
	accInfo.m_strPOPAccount	= _T( "" ); 
	accInfo.m_strPOPServer	= _T( "" ); 
	accInfo.m_strSenderName	= _T( "" ); 
	accInfo.m_strSMTPServer	= _T( "" ); 
 
	//{{AFX_DATA_INIT(CWizard) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
CWizard::CWizard(UINT nIDTemplate,CWnd* pParent /*=NULL*/) 
: CDialog( nIDTemplate, pParent) 
{ 
	m_nCurPage	= 0; 
	m_nPageCount	= 0; 
	m_pPageLink		= 0; 
 
	accInfo.m_bHotmail	= 0; 
	accInfo.m_strAccName	= _T( "" ); 
	accInfo.m_strEmlAddr	= _T( "" ); 
	accInfo.m_strMailPath	= _T( "" ); 
	accInfo.m_strPassword	= _T( "" ); 
	accInfo.m_strPOPAccount	= _T( "" ); 
	accInfo.m_strPOPServer	= _T( "" ); 
	accInfo.m_strSenderName	= _T( "" ); 
	accInfo.m_strSMTPServer	= _T( "" ); 
 
	//{{AFX_DATA_INIT(CWizard) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
void CWizard::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CWizard) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CWizard, CDialog) 
	//{{AFX_MSG_MAP(CWizard) 
	ON_BN_CLICKED(IDC_PREV, OnPrev) 
	ON_BN_CLICKED(IDC_NEXT, OnNext) 
	ON_BN_CLICKED(IDC_FINISH, OnFinish) 
	ON_BN_CLICKED(IDC_CANCEL, OnCancel) 
	ON_WM_DESTROY() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CWizard message handlers 
///////////////////////////////////////////////////////////////////////////// 
// CStep1 dialog 
 
 
CStep1::CStep1(CWnd* pParent /*=NULL*/) 
	: CDialog(CStep1::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CStep1) 
	m_strAccName = _T(""); 
	m_strMailPath = _T( "<默认>" ); 
	//}}AFX_DATA_INIT 
} 
 
 
void CStep1::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStep1) 
	DDX_Text(pDX, IDC_USER_NAME, m_strAccName); 
	DDV_MaxChars(pDX, m_strAccName, 20); 
	DDX_Text(pDX, IDC_EMAIL_PATH, m_strMailPath); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CStep1, CDialog) 
	//{{AFX_MSG_MAP(CStep1) 
	ON_BN_CLICKED(IDC_FILE_OPEN, OnBrowseForFolder) 
	ON_BN_CLICKED(IDC_DEFAULT, OnDefault) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStep1 message handlers 
///////////////////////////////////////////////////////////////////////////// 
// CStep2 dialog 
 
 
CStep2::CStep2(CWnd* pParent /*=NULL*/) 
	: CDialog(CStep2::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CStep2) 
	m_strSenderName = _T(""); 
	m_strEmlAddr = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CStep2::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStep2) 
	DDX_Text(pDX, IDC_SENDER_NAME, m_strSenderName); 
	DDX_Text(pDX, IDC_EMAIL_ADDRESS, m_strEmlAddr); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CStep2, CDialog) 
	//{{AFX_MSG_MAP(CStep2) 
		// NOTE: the ClassWizard will add message map macros here 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStep2 message handlers 
///////////////////////////////////////////////////////////////////////////// 
// CStep3 dialog 
 
 
CStep3::CStep3(CWnd* pParent /*=NULL*/) 
	: CDialog(CStep3::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CStep3) 
	m_strPOPServer = _T(""); 
	m_strPOPAccount = _T(""); 
	m_strPassword = _T(""); 
	m_strSMTPServer = _T(""); 
	m_bHotmail = 0; 
	//}}AFX_DATA_INIT 
} 
 
 
void CStep3::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStep3) 
	DDX_Text(pDX, IDC_POP3_SERVER, m_strPOPServer); 
	DDX_Text(pDX, IDC_POP3_USER, m_strPOPAccount); 
	DDX_Text(pDX, IDC_PASSWORD, m_strPassword); 
	DDX_Text(pDX, IDC_SMTP_SERVER, m_strSMTPServer); 
	DDX_Radio(pDX, IDC_POP3, m_bHotmail); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CStep3, CDialog) 
	//{{AFX_MSG_MAP(CStep3) 
	ON_BN_CLICKED(IDC_POP3, OnPop3) 
	ON_BN_CLICKED(IDC_HOTMAIL, OnHotmail) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStep3 message handlers 
///////////////////////////////////////////////////////////////////////////// 
// CStep4 dialog 
 
 
CStep4::CStep4(CWnd* pParent /*=NULL*/) 
	: CDialog(CStep4::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CStep4) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CStep4::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStep4) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CStep4, CDialog) 
	//{{AFX_MSG_MAP(CStep4) 
		// NOTE: the ClassWizard will add message map macros here 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStep4 message handlers 
 
void CWizard::AddPage(CDialog *pDialog, UINT nID) 
{ 
// Create a node and initialize its fields: 
	PAGELINK* pNewPage = new PAGELINK; 
	pNewPage->pDlg = pDialog; 
	pNewPage->Next = NULL;  
	pNewPage->nNum = ++m_nPageCount; 
 
// Insert this node into the list: 
	PAGELINK* pTemp = m_pPageLink; 
	if ( pTemp != 0 )	// A non-empty list. 
	{ 
		while ( pTemp->Next ) 
			pTemp = pTemp->Next; 
		pTemp->Next = pNewPage; 
	} 
	else	// An empty list: 
		m_pPageLink = pNewPage; 
 
// Create the dialog. 
	pNewPage->pDlg->Create( nID, this ); 
 
// Make sure that the dialog has been correctly created and its style is suitable: 
	ASSERT( ::IsWindow( pNewPage->pDlg->m_hWnd ) ); 
	DWORD dwStyle = pNewPage->pDlg->GetStyle(); 
	ASSERT( ( dwStyle & WS_CHILD ) && ( dwStyle & ~WS_BORDER ) ); 
 
// Show the dialog with the style SW_HIDE, and resize it within a rect: 
	pNewPage->pDlg->ShowWindow( SW_HIDE ); 
	pNewPage->pDlg->MoveWindow( m_wndPageRect ); 
} 
 
 
void CWizard::ShowPage( int nPos ) 
{ 
	PAGELINK* pTemp = m_pPageLink;  
	while( pTemp )  
	{  
		if( pTemp->nNum == nPos)  
		{ 
			pTemp->pDlg->ShowWindow( SW_SHOW ); 
		} 
		else 
			pTemp->pDlg->ShowWindow(SW_HIDE);  
		pTemp = pTemp->Next;  
	} 
	if( nPos >= m_nPageCount )	// The last page. 
	{  
		m_nCurPage = m_nPageCount; 
		SetWizButton( 2 ); 
		return; 
	} 
	if( nPos <= 1 )	// The first page. 
	{ 
		m_nCurPage = 1; 
		SetWizButton( 0 ); 
		return; 
	} 
	SetWizButton( 1 );	// Neither of the cases. 
} 
 
void CWizard::SetWizButton(int nFlag) 
{ 
	GetDlgItem( IDC_CANCEL )->EnableWindow( TRUE );  
	GetDlgItem( IDC_PREV )->EnableWindow( TRUE );  
	GetDlgItem( IDC_NEXT )->EnableWindow( TRUE );  
	GetDlgItem( IDC_FINISH )->EnableWindow( FALSE );  
	switch( nFlag)  
	{  
	case 0:		// The first step 
		GetDlgItem( IDC_PREV )->EnableWindow( FALSE );  
		break;  
	case 1:		// Intermediate step  
		break;  
	case 2:		// The last step 
		GetDlgItem( IDC_NEXT )->EnableWindow( FALSE ); 
		GetDlgItem( IDC_FINISH )->EnableWindow( TRUE ); 
		break; 
	} 
} 
 
BOOL CWizard::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	CRect mainDlgRect;  
	GetWindowRect( &mainDlgRect ); 
	int nCaption = ::GetSystemMetrics( SM_CYCAPTION ); 
	int nXEdge = ::GetSystemMetrics( SM_CXEDGE );   
	int nYEdge = ::GetSystemMetrics( SM_CYEDGE );  
	mainDlgRect.top		= mainDlgRect.top +	nCaption + nYEdge; 
	mainDlgRect.left	= mainDlgRect.left + 2 * nXEdge;  
 
	CRect embDlgRect; 
	GetDlgItem( IDC_POS )->GetWindowRect( &embDlgRect ); 
 
	m_wndPageRect.top		= embDlgRect.top	- mainDlgRect.top;  
	m_wndPageRect.left		= embDlgRect.left	- mainDlgRect.left;  
	m_wndPageRect.bottom	= embDlgRect.bottom	- mainDlgRect.top;  
	m_wndPageRect.right		= embDlgRect.right	- mainDlgRect.left;  
 
	CStep1* pStep1 = new CStep1; 
	CStep2* pStep2 = new CStep2; 
	CStep3* pStep3 = new CStep3; 
	CStep4* pStep4 = new CStep4; 
 
	AddPage( pStep1, IDD_STEP1 ); 
	AddPage( pStep2, IDD_STEP2 ); 
	AddPage( pStep3, IDD_STEP3 ); 
	AddPage( pStep4, IDD_STEP4 ); 
 
	ShowPage(1); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CWizard::OnCancel()  
{ 
	CDialog::OnCancel(); 
} 
 
void CWizard::OnPrev()  
{ 
	ShowPage( --m_nCurPage ); 
} 
 
void CWizard::OnNext()  
{ 
	PAGELINK* pTmpPageNode = m_pPageLink; 
	while( pTmpPageNode ) 
	{ 
		if( pTmpPageNode->nNum == m_nCurPage ) 
			break; 
		else 
			pTmpPageNode = pTmpPageNode->Next; 
	} 
	bool nCheckRes = true; 
	CDialog* pDlgTmp = pTmpPageNode->pDlg; 
	switch( m_nCurPage ) 
	{ 
		// UpdateAccInfo() function is employed for the sake of convenience for users. 
		// For now, it's not meaningful. It can be modified later. 
	case 1: 
		nCheckRes = ( ( CStep1* )pDlgTmp )->CheckForNullValues( ); 
		if( nCheckRes ) 
			( ( CStep1* )pDlgTmp )->UpdateAccInfo( accInfo ); 
		break; 
	case 2: 
		nCheckRes = ( ( CStep2* )pDlgTmp )->CheckForNullValues( ); 
		if( nCheckRes ) 
			( ( CStep2* )pDlgTmp )->UpdateAccInfo( accInfo ); 
		break; 
	case 3: 
		nCheckRes = ( ( CStep3* )pDlgTmp )->CheckForNullValues( ); 
		if( nCheckRes ) 
			( ( CStep3* )pDlgTmp )->UpdateAccInfo( accInfo ); 
		break; 
	default: 
		break; 
	} 
	if( nCheckRes ) 
	{ 
		ShowPage( ++m_nCurPage ); 
	} 
} 
 
void CWizard::OnFinish()  
{ 
	PAGELINK* pTmpPageNode = m_pPageLink; 
	while( pTmpPageNode ) 
	{ 
		if( pTmpPageNode->nNum == m_nPageCount ) 
			break; 
		else 
			pTmpPageNode = pTmpPageNode->Next; 
	} 
	( ( CStep4* )pTmpPageNode->pDlg )->UpdateData(); 
	( ( CStep4* )pTmpPageNode->pDlg )->UpdateAccInfo( accInfo ); 
 
	CDialog::OnOK(); 
} 
 
void CWizard::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
 
	PAGELINK* pTemp = m_pPageLink;  
	while( pTemp ) 
	{ 
		PAGELINK* pNextTemp = pTemp->Next; 
		pTemp->pDlg->DestroyWindow(); 
		delete pTemp->pDlg; 
		delete pTemp; 
		pTemp = pNextTemp; 
	} 
} 
 
void CStep1::OnBrowseForFolder()  
{ 
	CBrowseDirDialog dlg; 
	if( dlg.DoBrowse () ) 
	{ 
		m_strMailPath = dlg.m_Path  ; 
		GetDlgItem( IDC_EMAIL_PATH )->SetWindowText( m_strMailPath ); 
		GetDlgItem( IDC_EMAIL_PATH )->EnableWindow( TRUE ); 
	} 
} 
 
void CStep1::OnDefault()  
{ 
	m_strMailPath = _T( "<默认>" ); 
	GetDlgItem( IDC_EMAIL_PATH )->SetWindowText( m_strMailPath ); 
	GetDlgItem( IDC_EMAIL_PATH )->EnableWindow( FALSE ); 
} 
 
bool CStep1::CheckForNullValues() 
{ 
	UpdateData(); 
	if( m_strAccName.IsEmpty() ) 
	{ 
		MessageBox( "用户名称不能为空", "警告", MB_ICONWARNING | MB_APPLMODAL | MB_OK ); 
		return false; 
	} 
	if( m_strMailPath.IsEmpty() ) 
	{ 
		MessageBox( "邮件路径不能为空", "警告", MB_ICONWARNING | MB_APPLMODAL | MB_OK ); 
		return false; 
	} 
	return true; 
} 
 
bool CStep2::CheckForNullValues() 
{ 
	UpdateData( ); 
	if( m_strSenderName.IsEmpty() ) 
	{ 
		MessageBox( "\"发送者姓名\"不能为空", "警告", MB_ICONWARNING | MB_APPLMODAL | MB_OK ); 
		return false; 
	} 
	if( m_strEmlAddr.IsEmpty() ) 
	{ 
		MessageBox( "\"邮件地址\"不能为空", "警告", MB_ICONWARNING | MB_APPLMODAL | MB_OK ); 
		return false; 
	} 
	return true; 
} 
 
bool CStep3::CheckForNullValues() 
{ 
	UpdateData(); 
	if( m_strPOPServer.IsEmpty() ) 
	{ 
		MessageBox( "\"POP3服务器\"不能为空", "警告", MB_ICONWARNING | MB_APPLMODAL | MB_OK ); 
		return false; 
	} 
	/*if( m_strSMTPServer.IsEmpty() ) 
	{ 
		MessageBox( "\"邮件地址\"不能为空", "警告", MB_ICONWARNING | MB_APPLMODAL | MB_OK ); 
		return false; 
	}*/ 
	return true; 
} 
 
void CStep3::OnPop3()  
{ 
	m_bHotmail = 0; 
	CString strTmp; 
	strTmp.LoadString( IDS_POP3_POP3 ); 
	GetDlgItem( IDC_NOTE_POP3 )->SetWindowText( strTmp ); 
	 
	strTmp.Empty(); 
	strTmp.LoadString( IDS_POP3_SMTP ); 
	GetDlgItem( IDC_NOTE_SMTP )->SetWindowText( strTmp ); 
} 
 
BOOL CStep3::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	CString strTmp; 
	strTmp.LoadString( IDS_POP3_POP3 ); 
	GetDlgItem( IDC_NOTE_POP3 )->SetWindowText( strTmp ); 
	strTmp.Empty(); 
	strTmp.LoadString( IDS_POP3_SMTP ); 
	GetDlgItem( IDC_NOTE_SMTP )->SetWindowText( strTmp );	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CStep3::OnHotmail()  
{ 
	m_bHotmail = 1; 
	CString strTmp; 
	strTmp.LoadString( IDS_HOTMAIL_POP3 ); 
	GetDlgItem( IDC_NOTE_POP3 )->SetWindowText( strTmp ); 
	 
	strTmp.Empty(); 
	strTmp.LoadString( IDS_HOTMAIL_SMTP ); 
	GetDlgItem( IDC_NOTE_SMTP )->SetWindowText( strTmp ); 
} 
 
void CStep1::UpdateAccInfo( struct CWizard::AccInfo& accInfo) 
{ 
	accInfo.m_strAccName	= m_strAccName; 
	accInfo.m_strMailPath	= m_strMailPath; 
} 
 
void CStep2::UpdateAccInfo( struct CWizard::AccInfo& accInfo) 
{ 
	accInfo.m_strEmlAddr	= m_strEmlAddr; 
	accInfo.m_strSenderName	= m_strSenderName; 
} 
 
void CStep3::UpdateAccInfo( struct CWizard::AccInfo& accInfo) 
{ 
	accInfo.m_bHotmail		= m_bHotmail; 
	accInfo.m_strPassword	= m_strPassword; 
	accInfo.m_strPOPAccount	= m_strPOPAccount; 
	accInfo.m_strPOPServer	= m_strPOPServer; 
	accInfo.m_strSMTPServer	= m_strSMTPServer; 
} 
 
void CStep4::UpdateAccInfo( struct CWizard::AccInfo& accInfo) 
{ 
	// Store data into struct AccInfo in CWizard. 
}