void CLocalSearchMail::OnBnClickedButtonLocalsearch()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if ( m_strLocalPath.IsEmpty())
{
MessageBox("请选择您要搜索的路径!", "提示", MB_OK|MB_ICONINFORMATION);
return;
}
GetDlgItem(IDC_BUTTON_LOCALSEARCH)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_LOCALSEARCH)->EnableWindow(TRUE);
CString csFolder = m_strLocalPath;
if(csFolder.Right(1) != "\\")
csFolder += "\\";
csFolder += "*.*";
CFileFind filefind;
BOOL bContinue = filefind.FindFile(csFolder);
BOOL bFirst = TRUE;
CMailSearch search;
CString strBuf;
char szBuf[280];
CStringList strKeywordList;
char *pEMailFilter = m_strMailFilter.GetBuffer(m_strMailFilter.GetLength());
char *pKeyword = strtok(pEMailFilter, ",");
while ( pKeyword != NULL )
{
CString strKeyword = pKeyword;
strKeyword.TrimLeft();
strKeyword.TrimRight();
if ( !strKeyword.IsEmpty() )
{
strKeywordList.AddTail(strKeyword);
}
pKeyword = strtok(NULL, ",");
}
m_strMailFilter.ReleaseBuffer();
while(bContinue)
{
bContinue = filefind.FindNextFile();
if(!filefind.IsDots() && !filefind.IsDirectory() )
{
CStringList strMailList;
CString foundFileName = filefind.GetFilePath();
sprintf(szBuf, "正在搜索:%s", foundFileName);
::SendMessage(GetParent()->m_hWnd, WM_USER_SETSTATUSTEXT, 1, (LPARAM)szBuf);
FILE *fp = fopen(foundFileName, "rt");
while ( fgets(strBuf.GetBuffer(4096), 4096, fp) )
{
strBuf.ReleaseBuffer();
strMailList.RemoveAll();
search.SearchEmail(strBuf, "@", strMailList);
InsertListCtrl(strMailList, foundFileName, strKeywordList);
}
}
}
sprintf(szBuf, "搜索完成");
::SendMessage(GetParent()->m_hWnd, WM_USER_SETSTATUSTEXT, 1, (LPARAM)szBuf);
GetDlgItem(IDC_BUTTON_LOCALSEARCH)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_STOPSEARCH)->EnableWindow(FALSE);
}
阅读(3014) | 评论(0) | 转发(0) |