MFC 下载线程中,下载完了关掉程序..急..
一个DLG中,画面初期化中起一个线程,用来下载,同时画面用来表示下载进度,当线程中下载完成后,我想关掉下载画面,同时整个程序结束...咋办?现在我是下载完了,程序结束不了..
代码:
UINT DownExec(LPVOID pParam)
{
CWnd *pwnd;
pwnd = CWnd::FromHandle((HWND)pParam);
CProgressCtrl *m_Prog = (CProgressCtrl*)pwnd->GetDlgItem(IDC_PROGRESS1);
CInternetSession netSession;
char filebuf[1024];
CStdioFile *fTargFile;
CString strFileUrl,strDFileName,strPocPer;
CString strUpdateFile;
long lngFileSize = 0L;
int intBytesWrite =0,intPoc =0,intPocPer =0;
BOOL isReadOK = FALSE;
strFileUrl = KINGSOFT_FILE_PATH;
strDFileName.Format(_T("%s\\%s"),GetApp()->GetAppDir(),KINGSOFT_FILE_NAME);
try{
pwnd->SetDlgItemTextW(IDC_STA_STATE,_T("Loading..."));
fTargFile = netSession.OpenURL(strFileUrl,1,INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD);
lngFileSize = fTargFile->SeekToEnd();
fTargFile->SeekToBegin();
long lngReadBytes = 0L;
CFile fDestFile(strDFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
m_Prog->SetRange32(1,100);
while (intBytesWrite = fTargFile->Read(filebuf, 1024)){
isReadOK = TRUE;
lngReadBytes += intBytesWrite;
fDestFile.Write(filebuf, intBytesWrite);
m_Prog->SetPos((int)((double)lngReadBytes * 100.0/lngFileSize));
strPocPer.Format(_T("%d"),(int)((double)lngReadBytes * 100.0/lngFileSize));
pwnd->SetDlgItemText(IDC_STA_PRO,strPocPer + _T("%"));
}
if (isReadOK) {
intPocPer = 100;
strPocPer.Format(_T("%d"),intPocPer);
pwnd->SetDlgItemText(IDC_STA_PRO,strPocPer + _T("%"));
pwnd->SetDlgItemTextW(IDC_STA_STATE,_T("Downloaded"));
}
fDestFile.Close();
delete fTargFile;
((CDialog*)pwnd)->EndDialog(IDCLOSE);-->关掉对话框,退出程序,不好用?????
strUpdateFile.Format(_T("%s\\%s"), GetApp()->GetAppDir(), UPDATE_FILE);
//ShellExecute(NULL,L"open",strUpdateFile,L"",L"", SW_SHOW);
AfxEndThread(0);
}catch(CInternetException *IE){
}catch(CException *e){
}
return 0;
}
BOOL CDownLoadPro::OnInitDialog()
{
CWinThread* pThread = AfxBeginThread(DownExecKingsoft,GetSafeHwnd(),THREAD_PRIORITY_NORMAL);
return TRUE;
}
高手指点.....