下面是我对一个数据表查询的代码,请问如果我要开一个新的线程来处理这个select * from table 的查询,应该怎么改呢??BOOL CAbcdeView::ShowInformation(CString strSQL)
{
CRect rect;
CListCtrl& ctrlList = (CListCtrl&) GetListCtrl();
ctrlList.GetWindowRect(rect); try{
// get recordset field information
BeginWaitCursor();
if(m_pCommonRS->IsOpen()) m_pCommonRS->Close();
//m_pCommonRS->m_strFilter="";
CString strSQL=_T("select * from table1");
m_pCommonRS->Open(CRecordset::snapshot, strSQL);
if(!m_pCommonRS->IsEOF()){
m_pCommonRS->MoveLast(); 
m_pCommonRS->MoveFirst(); 
}
// get recordset data information

if(!m_pCommonRS->IsEOF()){
m_pCommonRS->MoveLast(); 
m_pCommonRS->MoveFirst(); 
}
int nFieldCount = m_pCommonRS->GetODBCFieldCount();
CODBCFieldInfo fieldinfo; 
for(int n=0;n<nFieldCount;n++){
m_pCommonRS->GetODBCFieldInfo(n, fieldinfo);
int nWidth = ctrlList.GetStringWidth(fieldinfo.m_strName) + 50;
ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
}
CString strValue; 
m_pCommonRS->MoveFirst(); 
int nCount = 0; while(!m_pCommonRS->IsEOF()){
ctrlList.InsertItem(nCount, strValue);
for(int j=0;j<nFieldCount;j++){
m_pCommonRS->GetFieldValue(j, strValue);
ctrlList.SetItemText(nCount, j, strValue);
}
m_pCommonRS->MoveNext(); 
nCount ++;
}

EndWaitCursor();
} catch(CDBException *e){
e->ReportError();
EndWaitCursor();
return FALSE;
} return TRUE;
}

解决方案 »

  1.   

    See the link below, so many samples there, FYI:http://www.codeproject.com/threads/#Threads
      

  2.   

    创建 m_pShowTray=AfxBeginThread(&ThreadName,NULL,
        THREAD_PRIORITY_NORMAL,0,
        CREATE_SUSPENDED);
    m_pShowTray->m_bAutoDelete=FALSE;
    m_pShowTray->ResumeThread();//线程的声明.cpp
    UINT ThreadName(LPVOID pParam)   
    {   
      return NULL;
    }//变量声明 .h
    CWinThread* m_pShowTray;
      

  3.   

    to: 跳动的心
    我按照你的方法写了,可是有个错误信息:
    I:\VC\abcde\abcdeView.cpp(128) : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'是什么意思呢?
      

  4.   

    我的代码是这样写的:m_pSelectThread=AfxBeginThread(ThreadFunction,NULL,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);ThreadFunction 是这样定义的:
    UINT ThreadFunction (LPVOID pParam)
    {
        return 0;
    }