CString fname[3000];
CString name[1024] ;
int j1 ;
int nIndex = 0;
void CDisposeXJXDlg::OnBtnSelSrcFile()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE, NULL, NULL ,OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT
|OFN_ALLOWMULTISELECT,"(*.fbd) | *.fbd||",AfxGetMainWnd());
TCHAR* pszFile =new TCHAR[MAX_PATH];
memset(pszFile,0,sizeof(TCHAR)*MAX_PATH);
dlg.m_ofn.lpstrFile = pszFile ;
if(IDOK==dlg.DoModal())
{
int i = 0 ;
POSITION pos ;
//把起始位置赋给pos
pos = dlg.GetStartPosition();
//把打开的多个文件名赋给fname数组
while(pos!=NULL)
{
fname[i] = dlg.GetNextPathName(pos);
name[i] = fname[i].Right(fname[i].GetLength()-fname[i].ReverseFind('\\')-1);
m_ListOutInfo.AddString(name[i]);
i++ ;
}
}
}
int t=0 ;
int tt = 0 ;
int TheradsCount = 0;
int j2 = 0;
CWinThread* pThread[MAX_THREADS];
void CDisposeXJXDlg::OnBtnTypeset()
{
GetDlgItem(IDC_BTN_TYPESET)->EnableWindow(FALSE);
TheradsCount = m_ListOutInfo.GetCount();
j2 = TheradsCount ;
for(int m1=0 ;j2<MAX_THREADS? m1<j2 :m1<MAX_THREADS ;m1++)
{
pThread[m1] =AfxBeginThread(CDisposeXJXDlg::ThreadFun,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pThread[m1]->ResumeThread();
}
}
UINT CDisposeXJXDlg::ThreadFun(LPVOID pParam)
{
CDisposeXJXDlg* dlg=(CDisposeXJXDlg*)pParam;
WaitForSingleObject(semaphoreWrite.m_hObject,INFINITE);
dlg->m_strFbdPath = fname[t];
dlg->StartDispose(fname[t]);
t++ ;
CloseHandle(pThread[tt]);
tt++ ;
ReleaseSemaphore(semaphoreWrite.m_hObject,1,NULL);
CloseHandle(pThread[tt]);
tt++ ;
return 0;
}
这是我自己写的,在MFC对话框里添加了一个列表框,打开多个文本然后点击按钮执行OnBtnTypeset()函数,最后想通过创建多个线程,同时调用StartDispose(fname[t])来处理多个文本,求大神们给指点,真心求教....谢谢了!
CString name[1024] ;
int j1 ;
int nIndex = 0;
void CDisposeXJXDlg::OnBtnSelSrcFile()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE, NULL, NULL ,OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT
|OFN_ALLOWMULTISELECT,"(*.fbd) | *.fbd||",AfxGetMainWnd());
TCHAR* pszFile =new TCHAR[MAX_PATH];
memset(pszFile,0,sizeof(TCHAR)*MAX_PATH);
dlg.m_ofn.lpstrFile = pszFile ;
if(IDOK==dlg.DoModal())
{
int i = 0 ;
POSITION pos ;
//把起始位置赋给pos
pos = dlg.GetStartPosition();
//把打开的多个文件名赋给fname数组
while(pos!=NULL)
{
fname[i] = dlg.GetNextPathName(pos);
name[i] = fname[i].Right(fname[i].GetLength()-fname[i].ReverseFind('\\')-1);
m_ListOutInfo.AddString(name[i]);
i++ ;
}
}
}
int t=0 ;
int tt = 0 ;
int TheradsCount = 0;
int j2 = 0;
CWinThread* pThread[MAX_THREADS];
void CDisposeXJXDlg::OnBtnTypeset()
{
GetDlgItem(IDC_BTN_TYPESET)->EnableWindow(FALSE);
TheradsCount = m_ListOutInfo.GetCount();
j2 = TheradsCount ;
for(int m1=0 ;j2<MAX_THREADS? m1<j2 :m1<MAX_THREADS ;m1++)
{
pThread[m1] =AfxBeginThread(CDisposeXJXDlg::ThreadFun,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pThread[m1]->ResumeThread();
}
}
UINT CDisposeXJXDlg::ThreadFun(LPVOID pParam)
{
CDisposeXJXDlg* dlg=(CDisposeXJXDlg*)pParam;
WaitForSingleObject(semaphoreWrite.m_hObject,INFINITE);
dlg->m_strFbdPath = fname[t];
dlg->StartDispose(fname[t]);
t++ ;
CloseHandle(pThread[tt]);
tt++ ;
ReleaseSemaphore(semaphoreWrite.m_hObject,1,NULL);
CloseHandle(pThread[tt]);
tt++ ;
return 0;
}
这是我自己写的,在MFC对话框里添加了一个列表框,打开多个文本然后点击按钮执行OnBtnTypeset()函数,最后想通过创建多个线程,同时调用StartDispose(fname[t])来处理多个文本,求大神们给指点,真心求教....谢谢了!