void CPage1::OnStartSearch() //开始 {
m_avi.Play(0,-1,100);
UpdateData(); m_i=0; m_nCur=0; //当前正在测试的那个 SetDlgItemText(IDC_STATE,"开始搜索了...");
m_list.DeleteAllItems(); CString str,strI; DWORD addr1,addr2; //初始化列表框显示 m_StartIP.GetAddress(addr1); m_EndIP.GetAddress(addr2); for(;addr1 <= addr2; addr1++) { m_tempIP.SetAddress(addr1); m_tempIP.GetWindowText(str); strI.Format("%d",m_i); m_i++; m_list.InsertItem(0,strI); m_list.SetItemText(0,1,str); } m_pp.SetRange(1,m_list.GetItemCount()); m_pp.SetPos(1);
if(this->m_bAutoStart) { if(m_list.GetItemCount() <= this->m_nThread) { for(int ij=0;ij AfxBeginThread(AutoSearchThread,this); } else { for(int ii=0; ii< this->m_nThread;ii++) AfxBeginThread(AutoSearchThread,this); }
}
} /*==================线程函数=自动搜索============================================*/ UINT AutoSearchThread(LPVOID lparam) { CPage1* pPage1=(CPage1*)lparam;
int nCur=pPage1->m_nCur; pPage1->m_nCur++; //用于指示 if(nCur > pPage1->m_list.GetItemCount()) pPage1->m_avi.Stop();
pPage1->m_list.SetItemText(nCur,3,"正在搜索和验证...");
char buf[200]; pPage1->m_list.GetItemText(nCur,1,buf,200); //获得选项的名称(FTP地址)
CInte.netSession session; CFtpConnection* pconn=NULL; try { pconn=session.GetFtpConnection(buf); } catch(CInternetException* pex) { pconn=NULL; pex->GetErrorMessage(buf,200); pPage1->m_list.SetItemText(nCur,2,"Error"); pPage1->m_list.SetItemText(nCur,3,buf); pex->Delete(); } if(pconn !=NULL) { pPage1->m_list.SetItemText(nCur,2,"OK"); pPage1->m_list.SetItemText(nCur,3,"已经验证通过"); pconn->Close(); delete pconn; } pPage1->m_pp.SetPos(pPage1->m_pp.GetPos()+1);
if(nCur< pPage1->m_list.GetItemCount()) //如果还每没有完,另开一个线程 AutoSearchThread(lparam);
return 0; }
/*==================线程函数1====手动搜索=========================================*/
UINT SearchFunction(LPVOID lparam) { CPage1* pPage1=(CPage1*)lparam;
int nIndex = pPage1->m_list.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); if(nIndex == -1) return 0; //获得所选择的项目
pPage1->m_list.SetItemText(nIndex,3,"正在搜索和验证...");
char buf[200]; pPage1->m_list.GetItemText(nIndex,1,buf,200); //获得选项的名称(FTP地址) CInternetSession session; CFtpConnection* pconn=NULL; try { pPage1->SetDlgItemText(IDC_STATE,buf); pconn=session.GetFtpConnection(buf); } catch(CInternetException* pex) { pconn=NULL; pex->GetErrorMessage(buf,200); pPage1->m_list.SetItemText(nIndex,2,"Error"); pPage1->m_list.SetItemText(nIndex,3,buf); pex->Delete(); } if(pconn !=NULL) { pPage1->m_list.SetItemText(nIndex,2,"OK"); pPage1->m_list.SetItemText(nIndex,3,"已经验证通过"); pconn->Close(); delete pconn; } return 0; } |