www.pudn.com > 20060410_reader_demo.rar > OE4Dlg.cpp, change:2000-02-06,size:4003b


// OE4Dlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "OE4.h" 
#include "OE4Dlg.h" 
#include "ShlObj.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// COE4Dlg dialog 
 
COE4Dlg::COE4Dlg(CWnd* pParent /*=NULL*/) 
	: CDialog(COE4Dlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(COE4Dlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void COE4Dlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(COE4Dlg) 
	DDX_Control(pDX, IDC_SUBJECTS, m_Subjects); 
	DDX_Control(pDX, IDC_FILES, m_Files); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(COE4Dlg, CDialog) 
	//{{AFX_MSG_MAP(COE4Dlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BTN_FOLDER, OnBtnFolder) 
	ON_LBN_DBLCLK(IDC_FILES, OnDblclkFiles) 
	ON_WM_DESTROY() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// COE4Dlg message handlers 
 
BOOL COE4Dlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void COE4Dlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
HCURSOR COE4Dlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void COE4Dlg::OnBtnFolder()  
{ 
BROWSEINFOA bi; 
TCHAR szFolder[MAX_PATH]; 
LPITEMIDLIST iil; 
 
	memset(&bi,0,sizeof(BROWSEINFOW)); 
	bi.hwndOwner=m_hWnd; 
	bi.pszDisplayName=szFolder; 
	bi.ulFlags=BIF_DONTGOBELOWDOMAIN; 
	iil=SHBrowseForFolder(&bi); 
	if(!iil) 
		return; 
 
	if(!SHGetPathFromIDList(iil,szFolder)) { 
		AfxMessageBox(TEXT("Invalid folder")); 
		return; 
	} 
	m_sPath=szFolder; 
	GetDlgItem(IDC_FOLDER)->SetWindowText(m_sPath); 
	UpdateFiles(); 
} 
 
BOOL COE4Dlg::UpdateFiles() 
{ 
HANDLE hFind; 
WIN32_FIND_DATA wfd; 
CString sPath=m_sPath; 
 
	m_Files.ResetContent(); 
	m_Subjects.ResetContent(); 
 
	if(sPath[sPath.GetLength()-1] != '\\') 
		sPath+="\\*.idx"; 
	else 
		sPath+="*.idx"; 
 
	hFind=FindFirstFile(sPath,&wfd); 
	if(hFind==INVALID_HANDLE_VALUE) 
		return FALSE; 
 
	do { 
		m_Files.AddString(wfd.cFileName); 
	}while(FindNextFile(hFind,&wfd)); 
 
	FindClose(hFind); 
	return TRUE; 
} 
 
void COE4Dlg::OnDblclkFiles()  
{ 
	if(m_Files.GetCurSel() < 0) 
		return; 
CString sFile;	 
 
	BeginWaitCursor(); 
 
	m_Subjects.ResetContent(); 
 
	m_Files.GetText(m_Files.GetCurSel(),sFile); 
	sFile=sFile.Left(sFile.GetLength()-4); 
 
	if(m_sPath[m_sPath.GetLength()-1] != '\\') 
		sFile=m_sPath+"\\"+sFile; 
	else 
		sFile=m_sPath+sFile; 
	m_Reader.Close(); 
	if(!m_Reader.OpenFile(sFile)) { 
		EndWaitCursor(); 
		AfxMessageBox(TEXT("Cannot open this file")); 
		return; 
	} 
	if(m_Reader.GetMessageCount() <= 0) { 
		m_Subjects.AddString("No messages in this folder"); 
		EndWaitCursor(); 
		return; 
	} 
	for(int i=0;i<m_Reader.GetMessageCount();i++) { 
		m_Subjects.AddString((char*)SUBJECT(m_Reader.GetMailbox(),i)); 
	} 
	EndWaitCursor(); 
} 
 
void COE4Dlg::OnDestroy()  
{ 
	m_Reader.Close(); 
	CDialog::OnDestroy(); 
}