首页 > 代码库 > C++ AfxBeginThread
C++ AfxBeginThread
计算从1+2+3...+100000=?
关键点
CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);
UINT MyFunction( LPVOID pParam );
实现过程
class CMfc01Dlg : public CDialog { // Construction public: CMfc01Dlg(CWnd* pParent = NULL); // standard constructor CWinThread *m_sumProc; // Dialog Data UINT SumPro(LPVOID pParam) { CMfc01Dlg *pDlg=(CMfc01Dlg*)pParam; __int64 nSum=0; char pszText[128]={0}; for (UINT i=1;i<100000;i++) { nSum+=i; memset(pszText,0,128); wsprintf(pszText,"累计到%d的结果为%I64d",i,nSum); pDlg->m_listbox1.AddString(pszText); } return 0; } void CMfc01Dlg::OnButton1() { // TODO: Add your control notification handler code here m_sumProc=AfxBeginThread(SumPro,this,0,0,0,NULL); }
void CMfc01Dlg::OnClose() { // TODO: Add your message handler code here and/or call default if (SumPro!=NULL) { DWORD dwExit=0; BOOL bRet=GetExitCodeThread(m_sumProc->m_hThread,&dwExit); if (dwExit==STILL_ACTIVE) { m_sumProc->ExitInstance(); delete m_sumProc; } } CDialog::OnClose(); }
|
图
备注
相关链接
来自为知笔记(Wiz)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。