void CXhDlg::OnButton1()
{
// TODO: Add your control notification handler code here
start.SetEvent();
return;
}void CXhDlg::OnButton2()
{
// TODO: Add your control notification handler code here
stop.SetEvent();
return;
}UINT CXhDlg::ThreadProc(LPVOID lParam)
{
WaitForSingleObject(start,INFINITE);
CInternetSession session;
CHttpFile *myHttpFile = NULL;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));
CString conn;
conn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
m_pConnection->Open(_bstr_t(conn),"","",adModeUnknown);
_variant_t RecordsAffected;
int type=0;
while( type++ < 80 )
{
bool flag = true;
int page=1;
while(flag)
{
WaitForSingleObject(stop,0);
CString m_SiteName;
m_SiteName.Format("%s%d%s%d","http://mmsg.qq.com/cgi-bin/gddylist?Type=",type,"&Sort=1&Page=",page++);
CString m_SiteInfo;
CString myData;
try
{
myHttpFile = (CHttpFile*)session.OpenURL(m_SiteName);
}
catch(CInternetException* m_pException)
{
delete myHttpFile;
m_pException->Delete();
return 0;
}
if ( myHttpFile )
{
while( myHttpFile->ReadString( myData ) )
{
m_SiteInfo+=myData;
}
}
int x1 = m_SiteInfo.Find("<div align=\"center\">");
int x2 = m_SiteInfo.Find("</div>",x1);
int x3 = m_SiteInfo.Find("/",x1);
CString s1 = m_SiteInfo.Mid(x1+20,x3-x1-20);
CString s2 = m_SiteInfo.Mid(x3+1,x2-x3-1);
if (s1 =="0" )
break;
if (s1 == s2)
{
flag=false;
} int t1 = m_SiteInfo.Find(">>",x1-100)+8;
int t2 = m_SiteInfo.Find("</td>",t1);
CString xtype = m_SiteInfo.Mid(t1,t2-t1); int find=0,find1=m_SiteInfo.Find("<td width=\"35%\" bgcolor=",x1)+20;
m_SiteInfo = m_SiteInfo.Right(m_SiteInfo.GetLength()-find1);
while( (find=m_SiteInfo.Find( "<td width=\"35%\" bgcolor=" , 1)) > 0 )
{
int find1 = m_SiteInfo.Find( ">",find)+1;
int find2 = m_SiteInfo.Find( "</td>" , find1);
CString content=m_SiteInfo.Mid( find1,find2-find1 );//主体
content.Replace("'","''");
content.Replace("\"","\"\"");
m_SiteInfo = m_SiteInfo.Right(m_SiteInfo.GetLength()-find2); CString sql;
sql.Format("insert into xh (xtype,content) values ('%s','%s')",xtype,content);
m_pConnection->Execute(_bstr_t(sql), &RecordsAffected, adCmdText);
::Sleep(200);
}
}
}
myHttpFile->Close();
session.Close();
MessageBox("完成");
return 0;
}
{
// TODO: Add your control notification handler code here
start.SetEvent();
return;
}void CXhDlg::OnButton2()
{
// TODO: Add your control notification handler code here
stop.SetEvent();
return;
}UINT CXhDlg::ThreadProc(LPVOID lParam)
{
WaitForSingleObject(start,INFINITE);
CInternetSession session;
CHttpFile *myHttpFile = NULL;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));
CString conn;
conn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
m_pConnection->Open(_bstr_t(conn),"","",adModeUnknown);
_variant_t RecordsAffected;
int type=0;
while( type++ < 80 )
{
bool flag = true;
int page=1;
while(flag)
{
WaitForSingleObject(stop,0);
CString m_SiteName;
m_SiteName.Format("%s%d%s%d","http://mmsg.qq.com/cgi-bin/gddylist?Type=",type,"&Sort=1&Page=",page++);
CString m_SiteInfo;
CString myData;
try
{
myHttpFile = (CHttpFile*)session.OpenURL(m_SiteName);
}
catch(CInternetException* m_pException)
{
delete myHttpFile;
m_pException->Delete();
return 0;
}
if ( myHttpFile )
{
while( myHttpFile->ReadString( myData ) )
{
m_SiteInfo+=myData;
}
}
int x1 = m_SiteInfo.Find("<div align=\"center\">");
int x2 = m_SiteInfo.Find("</div>",x1);
int x3 = m_SiteInfo.Find("/",x1);
CString s1 = m_SiteInfo.Mid(x1+20,x3-x1-20);
CString s2 = m_SiteInfo.Mid(x3+1,x2-x3-1);
if (s1 =="0" )
break;
if (s1 == s2)
{
flag=false;
} int t1 = m_SiteInfo.Find(">>",x1-100)+8;
int t2 = m_SiteInfo.Find("</td>",t1);
CString xtype = m_SiteInfo.Mid(t1,t2-t1); int find=0,find1=m_SiteInfo.Find("<td width=\"35%\" bgcolor=",x1)+20;
m_SiteInfo = m_SiteInfo.Right(m_SiteInfo.GetLength()-find1);
while( (find=m_SiteInfo.Find( "<td width=\"35%\" bgcolor=" , 1)) > 0 )
{
int find1 = m_SiteInfo.Find( ">",find)+1;
int find2 = m_SiteInfo.Find( "</td>" , find1);
CString content=m_SiteInfo.Mid( find1,find2-find1 );//主体
content.Replace("'","''");
content.Replace("\"","\"\"");
m_SiteInfo = m_SiteInfo.Right(m_SiteInfo.GetLength()-find2); CString sql;
sql.Format("insert into xh (xtype,content) values ('%s','%s')",xtype,content);
m_pConnection->Execute(_bstr_t(sql), &RecordsAffected, adCmdText);
::Sleep(200);
}
}
}
myHttpFile->Close();
session.Close();
MessageBox("完成");
return 0;
}
解决方案 »
- 新手使用bcg库,总是链接报错,为什么?
- 有人用过音频解编码库libspeex吗?急!急!急!急!
- 请问MSDN的例子中有没有抓屏的程序
- 求牛人帮助做三维撒球数组!散分!
- 关于SNMP的疑问,求高手指教
- 位图显示问题,急!!!高手请Help me!!!
- 请问,,c#,C++,c++builder,visual c++等有什么区别!!!我到底需要学习哪个???
- 谁知道广州哪里有英文原版的书卖?
- 怎么让弹出式菜单限制在列表控件里面
- 请帮忙解决一个数据库的问题
- 奇怪!在CFormView程序中,当拖滚动条后,窗体被覆盖的部分字体,画笔怎么都恢复了?
- 关于RichEdit控件导入图标后拷贝粘贴的问题!
BOOL CXhDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
HWND hWnd=GetSafeHwnd();
AfxBeginThread(ThreadProc,hWnd);
return TRUE; // return TRUE unless you set the focus to a control
}
--------------------Configuration: xh - Win32 Release--------------------
Compiling...
xhDlg.cpp
D:\VC\xh\xhDlg.cpp(123) : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
Error executing cl.exe.xh.exe - 1 error(s), 0 warning(s)
{
CoInitialize(NULL);
{
.....
} CoUninitialize();
}
{
WaitForSingleObject(((CXhDlg *)lParam)->start,INFINITE);
CoInitialize(NULL);
CInternetSession session;
CHttpFile *myHttpFile = NULL;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));
CString conn;
conn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
m_pConnection->Open(_bstr_t(conn),"","",adModeUnknown);
_variant_t RecordsAffected;
int type=0;
while( type++ < 80 )
{
bool flag = true;
int page=1;
while(flag)
{
WaitForSingleObject(((CXhDlg *)lParam)->stop,0);
CString m_SiteName;
m_SiteName.Format("%s%d%s%d","http://mmsg.qq.com/cgi-bin/gddylist?Type=",type,"&Sort=1&Page=",page++);
CString m_SiteInfo;
CString myData;
try
{
myHttpFile = (CHttpFile*)session.OpenURL(m_SiteName);
}
catch(CInternetException* m_pException)
{
delete myHttpFile;
m_pException->Delete();
return 0;
}
if ( myHttpFile )
{
while( myHttpFile->ReadString( myData ) )
{
m_SiteInfo+=myData;
}
}
int x1 = m_SiteInfo.Find("<div align=\"center\">");
int x2 = m_SiteInfo.Find("</div>",x1);
int x3 = m_SiteInfo.Find("/",x1);
CString s1 = m_SiteInfo.Mid(x1+20,x3-x1-20);
CString s2 = m_SiteInfo.Mid(x3+1,x2-x3-1);
if (s1 =="0" )
break;
if (s1 == s2)
{
flag=false;
} int t1 = m_SiteInfo.Find(">>",x1-100)+8;
int t2 = m_SiteInfo.Find("</td>",t1);
CString xtype = m_SiteInfo.Mid(t1,t2-t1); int find=0,find1=m_SiteInfo.Find("<td width=\"35%\" bgcolor=",x1)+20;
m_SiteInfo = m_SiteInfo.Right(m_SiteInfo.GetLength()-find1);
while( (find=m_SiteInfo.Find( "<td width=\"35%\" bgcolor=" , 1)) > 0 )
{
int find1 = m_SiteInfo.Find( ">",find)+1;
int find2 = m_SiteInfo.Find( "</td>" , find1);
CString content=m_SiteInfo.Mid( find1,find2-find1 );//Ö÷Ìå
content.Replace("'","''");
content.Replace("\"","\"\"");
m_SiteInfo = m_SiteInfo.Right(m_SiteInfo.GetLength()-find2); CString sql;
sql.Format("insert into xh (xtype,content) values ('%s','%s')",xtype,content);
m_pConnection->Execute(_bstr_t(sql), &RecordsAffected, adCmdText);
::Sleep(200);
}
}
}
myHttpFile->Close();
session.Close();
CoUninitialize();
return 0;
}改成上面的代码,错误提示为:
--------------------Configuration: xh - Win32 Release--------------------
Compiling...
xhDlg.cpp
D:\VC\xh\xhDlg.cpp(192) : error C2724: 'ThreadProc' : 'static' should not be used on member functions defined at file scope
Error executing cl.exe.xh.exe - 1 error(s), 0 warning(s)
{
public:
static WINAPI UINT ThreadProc1(LPVOID lParam);
}XhDlg.cpp
BOOL CXhDlg::OnInitDialog()
{
CDialog::OnInitDialog(); ......
//HWND hWnd=GetSafeHwnd();
AfxBeginThread(ThreadProc1,(LPVOID)this);
return TRUE; // return TRUE unless you set the focus to a control
}UINT CXhDlg::ThreadProc1(LPVOID lParam)
{
CXhDlg *p=(CXhDlg*)lParam;
CoInitialize(NULL);
{
p->ThreadProc();
}
CoUninitialize();
return 0;
}UINT CXhDlg::ThreadProc(LPVOID lParam)
{
你的代码。。
}
你好,你的代码我还是调不通,您调过的吗?