我现在想多开一个线程来在后台自动读取某些文件。线程处理函数的代码如下:
UINT CXianZhiGongMaoView::ShuJuDuQu(LPVOID pParam)
{
DWORD dwArg=*(DWORD*)pParam;
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
CXianZhiGongMaoDoc* testdata=(CXianZhiGongMaoDoc*)pMainFrame->GetActiveDocument();
if (testdata->m_gangcaidatalist.IsEmpty())
testdata->SetZiYuan_count(0);
extern CString exceldir;
CXianZhiGongMaoView* pView;
pView=(CXianZhiGongMaoView*)pMainFrame->GetActiveView();
pView->m_test.SetWindowText(exceldir);
CFileFind excelfile;
CString dir=exceldir+"\\*.xls";
BOOL bexceldir=excelfile.FindFile(dir);
while (bexceldir)
{
bexceldir=excelfile.FindNextFile();
CString filename=excelfile.GetFileName();
dir=exceldir+"\\"+filename;
// testdata->NewGangCaiData(dir);
}
return 0;
}
在声明中添加static关键字,不然无法开多线程。线程的处理函数视图类的成员函数,所以无法直接用GetDocument()来获取文档指针。可是才用上面的方法,在第一句获取窗口的指针就失败,后面第二句就会报wincore 991错误,怎么解决?因为要读取的文件内容很多,不开多线程在后台读取,程序界面会一直卡着直到全部读取完。