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
);
实现过程
|
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();
}
|
图
备注
相关链接
C++ AfxBeginThread的更多相关文章
- VC++ 结束线程 AfxBeginThread AfxEndThread
如果你的线程是从CWinThread继承出来的,结束自己就用AfxEndThread, 如果是外部调用的话,可以用PostThreadMessage(m_nThreadID, WM_QUIT,0,0) ...
- VC++ AfxBeginThread 与 CreateThread 的区别
简言之:AfxBeginThread是MFC的全局函数,是对CreateThread的封装. CreateThread是Win32 API函数,前者最终要调到后者.具体说来,CreateThre ...
- 使用MFC中的AfxBeginThread创建多线程
创建一个基于对话框的工程,工程名为CreateThreadRect 在CreateThreadRect.cpp中增加一个ThreadProc函数,代码如下 工作者线程的函数必须是全局函数或静态 ...
- AfxBeginThread和AfxEndThread+内存泄露
ref http://blog.csdn.net/kut00/article/details/4209680 启动线程: CWinThread* AfxBeginThread( 线程函数, this ...
- 多线程 AfxBeginThread 与 CreateThread 的区别
简言之: AfxBeginThread是MFC的全局函数,是对CreateThread的封装. CreateThread是Win32 API函数,前者最终要调到后者. 1>.具体说来,Cr ...
- AfxBeginThread的介绍/基本用法
AfxBeginThread 用户界面线程和工作者线程都是由AfxBeginThread创建的.现在,考察该函数:MFC提供了两个重载版的AfxBeginThread,一个用于用户界面线程,另一 ...
- 工作线程AfxBeginThread的使用
工作线程通常用来执行一些后台任务,如:数据计算.后台杀毒等等.因为不需要创建窗口和处理用户消息,编写比较容易,在程序中只要调用AfxBeginThread 函数就可以创建并启动一个工作线程了. Afx ...
- 用户界面线程AfxBeginThread的使用
用户界面线程在运行时会有一个窗口界面和与其相对应的窗口函数,所以它可以通过响应消息来和用户进行交互. AfxBeginThread 函数原型如下: CWinThread *AfxBeginThread ...
- CreateThread、_beginthreadex和AfxBeginThread 的区别
CreateThread._beginthreadex和AfxBeginThread 创建线程好几个函数可以使用,可是它们有什么区别,适用于什么情况呢?参考了一些资料,写得都挺好的,这里做一些摘抄和整 ...
随机推荐
- OLAP、OLTP的介绍和比较 via csdn
OLAP.OLTP的介绍和比较 数据处理大致可以分成两大类: OLTP(On-Line Transaction Processing)联机事务处理 也称为面向交易的处理系统,其基本特征是顾客的原始数据 ...
- HDU 5744 Keep On Movin
Keep On Movin Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- codeforces 675D Tree Construction set
转自:http://blog.csdn.net/qwb492859377/article/details/51447350 #include <stdio.h> #include < ...
- bzoj 1001: [BeiJing2006]狼抓兔子 平面图最小割
平面图跑最大流 可以转换为其对偶图跑最短路 一个环对应一个割 找到最小环(即最短路)极为所求,注意辅助边的建立 加入读入优化 不过时间还是一般 估计是dij写的不好 大神勿喷~~~ /*** ...
- hdu 4720 计算几何简单题
昨天用vim练了一道大水题,今天特地找了道稍难一点的题.不过也不是很难,简单的计算几何而已.练习用vim编码,用gdb调试,结果居然1A了,没调试...囧... 做法很简单,无非就是两种情况:①三个巫 ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_selected_list_value(self, locator)
def get_selected_list_value(self, locator): """Returns the value of the selected elem ...
- 学习笔记 - 深究Bitmap压缩避免OOM的核心inSampleSize的最佳取值
/** * 测试代码,通过在SDCard根目录放置几种不同大小的图片, 来自动测试压缩方式是否有效同时看是否会内存不够. * * @since * By:AsionTang * At:2014年3月2 ...
- ORA-15041: diskgroup space exhausted
今天在做一个备份的时候,出现磁盘耗尽的错误,具体如下: RMAN-00571: =========================================================== ...
- 使用PPA在ubuntu上安装emacs
使用PPA(Personal Package Archive)在ubuntu上安装emacs 1添加 PPA 到 apt repository 中: $ sudo add-apt-reposito ...
- PHP中的替代语法
今天看了一下wordpress的代码,里面有些少见的php替代语法, <?php else : ?> <div class="entry-content"> ...