首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

有时当在ContinueModal()中,为什么怎么解决

2012-04-27 
有时当在ContinueModal()中,为什么如何解决?bool CFileMDIDoc::StartFileThread(LPCTSTR lpszFileName,int

有时当在ContinueModal()中,为什么如何解决?
bool CFileMDIDoc::StartFileThread(LPCTSTR lpszFileName,int Type)
{
TRACE(_T("CFileMDIDoc::StartFileThread start\n"));

CMainFrame* pMainWnd=NULL;
pMainWnd = (CMainFrame*)::AfxGetMainWnd();
int result=1;
CBusyGIFProcessdlgProcessdlg(pMainWnd);

if (m_bModal)
{
Processdlg.SetDocument(this,Type);
Processdlg.m_bModel=true;
m_pProgPara.pWndProg=&Processdlg;

}
else
{
m_pProDlg=new CBusyGIFProcessdlg;
m_pProDlg->Create(IDD_BUSY_PROGRESS,pMainWnd);
m_pProDlg->SetDocument(this,Type);
m_pProDlg->m_bModel=false;
m_pProgPara.pWndProg=m_pProDlg;
m_pProDlg->CenterWindow();
m_pProDlg->ShowWindow(SW_SHOW);
}


DWORD dwID=0;
m_pProgPara.szFileName=lpszFileName;
m_pProgPara.pDoc=this;
m_pProgPara.pWnd=pMainWnd;
m_pProgPara.Type=Type;
  
  for(int i = 0; i < m_pProgPara.nHandleNum; i++)
{
m_pProgPara.hAry[i] = ::CreateEvent(NULL, false, true, NULL);
}
m_pProgPara.hThread = ::CreateThread(
NULL, 0, &ThreadProgress, &m_pProgPara,CREATE_SUSPENDED, &dwID);
 
if (m_bModal)
result=Processdlg.DoModal();
else
::ResumeThread(m_pProgPara.hThread);



if (m_bIsEsc)
m_bIsEsc=false;
if (result!=1) return false;//表示有中断

TRACE(_T("CFileMDIDoc::StartFileThread End\n"));

return true;
}
bool CFileMDIDoc::DocResumeThread()
{
::ResumeThread(m_pProgPara.hThread);
return true;
}

DWORD WINAPI CFileMDIDoc::ThreadProgress(LPVOID lParam)
{

DWORD dwStartTime = 0;
DWORD dwEndTime = 0;
dwStartTime = GetTickCount();
ProgParaThread *pProgPara=(ProgParaThread*)lParam;

CWnd* pWnd=pProgPara->pWnd;
CMainFrame* pMainWnd = NULL;
CString nPathName;
nPathName=pProgPara->szFileName;
pMainWnd=(CMainFrame*)pWnd;
CFileMDIDoc* pDoc=NULL;
pDoc=(CFileMDIDoc*)pProgPara->pDoc;

::WaitForMultipleObjects(pProgPara->nHandleNum, pProgPara->hAry, true, INFINITE);
if (pProgPara->Type==0)//打开
bool su=pDoc->DoThreadOpenDocument(nPathName);
else if (pProgPara->Type==1)//保存
pDoc->DoThreadSaveDocument(nPathName);



if(!pDoc->m_bFileScuess)
{
//不成功,发消息关闭对话框
CWnd* pWnd2=((ProgParaThread*)lParam)->pWndProg;
::SendMessage(pWnd2->m_hWnd, WM_CLOSE, 0, 0);
}
// close handle of synchronal signal handle
for(int i = 0; i < pProgPara->nHandleNum; i++) 
{
if(pProgPara->hAry[i])
{
::CloseHandle(pProgPara->hAry[i]);
pProgPara->hAry[i] = NULL;
}
}

// close handle of thread
if(pProgPara->hThread != NULL) 
{
::CloseHandle(pProgPara->hThread);
pProgPara->hThread = NULL;
}
dwEndTime = GetTickCount(); 
if((dwEndTime - dwStartTime) < 5000)
{
Sleep(5000);//如果时间太短,要做delay
}

return 0;
}

BOOL CFileMDIDoc::DoThreadOpenDocument(LPCTSTR lpszPathName)
{
if(!CDocument::OnOpenDocument(lpszPathName))
{
return FALSE;
}
return TRUE;
}
BOOL CFileMDIDoc::DoThreadSaveDocument(LPCTSTR lpszPathName)
{
BOOL bre=FALSE;
bre=CDocument::OnSaveDocument(lpszPathName);
return bre;
}
BOOL CFileMDIDoc::StepProgItem(int value)
{
if (m_pProgPara.hThread==NULL) return FALSE;
if(m_nProgPos < MANY_TOTAL)
{
m_nProgPos+=1;
::SendMessage(m_pProgPara.pWndProg->m_hWnd, WM_ZPPROGRESSSTEPIT, (WPARAM)m_nProgPos, 0);

}
return TRUE;
}

 BOOL CFileMDIDoc::DeoxidizeFile(LPCTSTR lpszPathName)


 {
//处理正在保存时取消
//1>删除不完整的档案
//2>还原旧文件及标题
BOOL bsu=::DeleteFile(lpszPathName);
SetTitle(m_OldFile);
SetModifiedFlag(m_bOldModi); 

return TRUE;
 }
 bool CFileMDIDoc::CheckProgThreadACTIVE()
{
if (m_pProgPara.hThread!=NULL)
{
DWORD dwExitCode;
bool bsu=GetExitCodeThread(m_pProgPara.hThread, &dwExitCode);
if (dwExitCode==STILL_ACTIVE)
{
return false;
}
}
return true;
}

void CFileMDIDoc::OnFileSave() 
{
// TODO: Add your command handler code here
CString strPathName= GetPathName();
if(!strPathName.IsEmpty())
{
OnSaveDocument(strPathName);//不提示框
return ;
}
CString str_Path="";
if(str_Path=="")
{
LPITEMIDLIST pidl;  
LPMALLOC pShellMalloc;  
char szDir[MAX_PATH];  

if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))  
{  
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl)))  
{  
//如果成功返回true  
if(SHGetPathFromIDList(pidl, szDir))  
{  
str_Path = szDir; //设置默认路径为"我的文档"的路径
str_Path+="\\Data";
}
pShellMalloc->Free(pidl);  
}
pShellMalloc->Release();  

}
CString str_FileName="a";
TCHAR lpstrFilename[MAX_PATH] ;
strcpy(lpstrFilename, str_FileName);
CFileDialogdlg(FALSE,"",strPathName);
dlg.m_ofn .lpstrFile=lpstrFilename;
dlg.m_ofn.lpstrInitialDir=str_Path;

if(dlg.DoModal() == IDOK)
{
CString strDlgTitile = dlg.GetFileTitle();
CString strDlgPathName = dlg.GetPathName();
CString strDlgFile = strDlgTitile + "." + "md5";

CStringstrPath;
int pos=strDlgPathName.ReverseFind('\\');
if (pos<0) return ;
strPath = strDlgPathName.Left(pos+1);

strDlgFile = strPath + strDlgFile;// "\\" +

OnSaveDocument(strDlgFile); 
SetPathName(strDlgFile);
}
}



BOOL CFileMDIDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
//if (!CDocument::OnOpenDocument(lpszPathName))
//return FALSE;

bool bsu=StartFileThread(lpszPathName,0);
if (!bsu) return FALSE;
// TODO: Add your specialized creation code here

return TRUE;
}

//CBusyGIFProcessdlg为进度条对话框
void CBusyGIFProcessdlg::OnProgressStepItem(WPARAM wParam,LPARAM lParam)
{

int value=wParam;
int pos=m_ProgressCtrl.GetPos();
if(value>=RANGE_MAXPROG)
{

m_ProgressCtrl.SetPos(RANGE_MAXPROG);
CString str;
str.LoadString(IDS_STRING_FILESCUESS);

OnOK();
}
else
m_ProgressCtrl.SetPos(value);
}

[解决办法]
又发一遍?
[解决办法]
查看一下call stack等

热点排行