大家好。我是vc的初学者,刚写一个匿名ftp扫描器,可以实现扫描(如图),但是扫描的过程中我点取消结束不了程序(点取消它显示没有响应),我用的是系统生成的void CScanFtpDlg::OnCancel() ,请各位高手如何才能在扫描的过程中结束程序?在下在这里先谢谢大家了。
解决方案 »
- MFC中文件的读取问题
- 调试器挂了啊啊
- Web页面中的ActiveX控件怎样知道浏览器是中文还是英文环境的呢?
- 请高手给我一个建议(绝对给分!)
- 我的电脑被唢只能上http://yefeng.8u8.com/这个网站,有什么办法解决呢?
- 浏览器的好多属性被修改了,还有任务栏的时间显示也被修改了,分析
- 求《COM原理与应用》的Sample Code
- vc++ 6.0 在win7上怎么不能生成dll文件了
- WinXP VC++6.0系统如何捕获所有系统中断和系统消息
- COleDateTime and datetime in VC - SQL SERVER
- 回车响应CBitmapButton消息处理函数的问题
- 在Win32下用什么API可以在窗口创建之后改变窗口左上角的标题文字?
void CScanFtpDlg::OnScanFtpServer()
{
int first, secnod, third, forth;
char buffer[20];
_ConnectionPtr pConn = connect_sqlserver();
GetDlgItem(IDC_SCANNING_STATIC)->SetWindowText("正在扫描,请稍后……");
for (first = m_StartIP1; (m_StartIP1 <= m_EndIP1); m_StartIP1++)
{
for (secnod = m_StartIP2; (m_StartIP2 <= m_EndIP2); m_StartIP2++)
{
for (third = m_StartIP3; (m_StartIP3 <= m_EndIP3); m_StartIP3++)
{
for (forth = m_StartIP4; (m_StartIP4 <= m_EndIP4); m_StartIP4++)
{
m_bConnectionAttempted = true;
CString IP;
m_pInetSession = new CInternetSession(AfxGetAppName(), 1,
PRE_CONFIG_INTERNET_ACCESS);
try
{
CString IPString2 = _itoa(m_StartIP2, buffer, 10);
CString IPString3 = _itoa(m_StartIP3, buffer, 10);
CString IPString4 = _itoa(m_StartIP4, buffer, 10);
IP = CString(_itoa(m_StartIP1, buffer, 10)) + "."
+ IPString2 + "." + IPString3 + "." + IPString4;
m_pFtpConnection = m_pInetSession->GetFtpConnection(IP);
}
catch(CInternetException *pEx)
{
//AfxMessageBox("连接ftp服务器时出现异常!");
m_pFtpConnection = NULL;
}
if (m_pFtpConnection != NULL)
{
writein_site(IP,pConn);
}
}
}
}
}
GetDlgItem(IDC_SCANNING_STATIC)->SetWindowText("");
AfxMessageBox("扫描完毕,匿名站点已添加至数据库中!");
}vc的初学者,代码写得很烂,大家将就这看吧,请大家给我指导下,谢谢大家了。
你这个函数还在for循环里跑,你点鼠标它怎么会有反应嘛.
它不会因为你点button就跳出for循环跑到你的oncancel里去执行的.学习一下多线程技术和事件相应.
DWORD WINAPI ThreadProc( LPVOID lpParameter )
{
CScanFtpDlg* pDlg = (CScanFtpDlg*)lpParameter;
int first, secnod, third, forth;
char buffer[20];
_ConnectionPtr pConn = pDlg->connect_sqlserver();
//GetDlgItem(IDC_SCANNING_STATIC)->SetWindowText("正在扫描,请稍后……");
for (first = pDlg->m_StartIP1; (pDlg->m_StartIP1 <= pDlg->m_EndIP1); pDlg->m_StartIP1++)
{
for (secnod = pDlg->m_StartIP2; (pDlg->m_StartIP2 <= pDlg->m_EndIP2); pDlg->m_StartIP2++)
{
for (third = pDlg->m_StartIP3; (pDlg->m_StartIP3 <= pDlg->m_EndIP3); pDlg->m_StartIP3++)
{
for (forth = pDlg->m_StartIP4; (pDlg->m_StartIP4 <= pDlg->m_EndIP4); pDlg->m_StartIP4++)
{
pDlg->m_bConnectionAttempted = true;
CString IP;
pDlg->m_pInetSession = new CInternetSession(AfxGetAppName(), 1,
PRE_CONFIG_INTERNET_ACCESS);
try
{
CString IPString2 = _itoa(pDlg->m_StartIP2, buffer, 10);
CString IPString3 = _itoa(pDlg->m_StartIP3, buffer, 10);
CString IPString4 = _itoa(pDlg->m_StartIP4, buffer, 10);
IP = CString(_itoa(pDlg->m_StartIP1, buffer, 10)) + "."
+ IPString2 + "." + IPString3 + "." + IPString4;
pDlg->m_pFtpConnection = pDlg->m_pInetSession->GetFtpConnection(IP);
}
catch(CInternetException *pEx)
{
//AfxMessageBox("连接ftp服务器时出现异常!");
pDlg->m_pFtpConnection = NULL;
}
if (pDlg->m_pFtpConnection != NULL)
{
pDlg->writein_site(IP,pConn);
}
if (pDlg->m_ThreadExit)
{
ExitThread(0);
}
}
}
}
}
return 0; }
void CScanFtpDlg::OnScanFtpServer()
{
UpdateData();
DWORD ThreadID;
GetDlgItem(IDC_SCANNING_STATIC)->SetWindowText("正在扫描,请稍后……");
m_hTread = CreateThread(NULL,0,ThreadProc,(LPVOID)this,0,&ThreadID);//产生新的线程,扫描IP
GetDlgItem(IDC_SCANNING_STATIC)->SetWindowText("");
AfxMessageBox("扫描完毕,匿名站点已添加至数据库中!");
}void CScanFtpDlg::OnStop()
{
m_ThreadExit = TRUE;
}
大家好。我今天猛看了一天的多线程编程,不管懂不懂,还是凑成了一段代码,但是不知道为什么OnScanFtpServer() 并没有产生新的进程。那位高手帮在下看下吧,星期五就要交这个小项目了,在下万分感谢。