Search This Blog

Thursday, May 14, 2009

WorkerThread Implementation



class CWorkerThreadImplementationDlg : public CDialog
{
     typedef struct DLG_STRUCT
     {
          CWorkerThreadImplementationDlg* _this;
     }DLG_STRUCT , *PDLGSTRUCT;


void CWorkerThreadImplementationDlg::OnBnClickedOk()
{    
     //CString *cstrValue = new CString("Hai");
     //AfxBeginThread( CWorkerThreadImplementationDlg::RunProgress , (LPVOID)cstrValue );
    
     PDLGSTRUCT lpDLG1 = new DLG_STRUCT;
     lpDLG1->_this = this;
     AfxBeginThread( CWorkerThreadImplementationDlg::RunProgress1 , lpDLG1 );
     PDLGSTRUCT lpDLG2 = new DLG_STRUCT;
     lpDLG2->_this = this;
     AfxBeginThread( CWorkerThreadImplementationDlg::RunProgress2 , lpDLG2 );
}

UINT CWorkerThreadImplementationDlg::RunProgress( LPVOID lpThreadParam )
{
     CString pstr = *((CString*)lpThreadParam);
     return 1;
}

UINT CWorkerThreadImplementationDlg::RunProgress1( LPVOID lpThreadParam )
{
     PDLGSTRUCT pstr = (PDLGSTRUCT)lpThreadParam;
     int nPos = 0;
     while( nPos < 100 )
     {
          pstr->_this->m_Progress1.SetPos( nPos++ );
          Sleep( 100 );
     }
     return 1;
}
UINT CWorkerThreadImplementationDlg::RunProgress2( LPVOID lpThreadParam )
{
     PDLGSTRUCT pstr = (PDLGSTRUCT)lpThreadParam;
     int nPos = 0;
     while( nPos < 100 )
     {
          pstr->_this->m_Progress2.SetPos( nPos++ );
          Sleep( 100 );    
     }
     return 1;
}

No comments: