Again, this new version of the program seems to run just like the preceding version. However, the program is now using both event objects and user-defined Windows messages to communicate between the main program and the thread. No more messing with clunky global variables.One big difference from previous versions of the program is that the secondary thread is begun in the OnCreate() function, which is called when the application first runs and creates the view. However, because the first line of the thread function is the call to WaitForSingleObject(), the thread immediately suspends execution and waits for the threadStart event to be signaled.When the threadStart event object is signaled, the thread is free to display the message box and then enter its while loop, where it polls the threadEnd event object. The while loop continues to execute until threadEnd is signaled, at which time the thread sends the WM_THREADENDED message to the main program and exits. Because the thread is started in OnCreate(), after the thread ends, it can't be restarted.
解决方案 »
- com编程出现问题。。。客户端调用CreateInstance时出错 。。。。请帮忙 解决给200分 不够再加
- 求助,。关于mfc
- setclasslong怎么老修改不了窗口的背景色?
- 如何在对话框显示一个网格的控件,而且如何把一个文件的一个一个字的在每个网格内填入和并能进行编辑。有这样的控件吗? 如何去完成?(V
- 关于隐藏进程的问题__过年大送分<2>
- 编译directX 时 报错:找不到sal.h,请各位帮忙解决下
- 如何设置窗口最大化时的位置和大小
- 请教vc下如何实现从csring 到ctime 的转换???!!!!
- 如何实现浮动工具条? 高分!!!
- 关于TAPI的简单问题,大仙小仙们快救我!
- 怎样将些好的CLASS 封装成 DLL 和 LIB
- [求助]怎样使鼠标自动在全屏范围内,作直线移动碰到边角就自然撞回?
与前一版本程序的一个很大的区别是,第二个线程是在OnCreate函数里产生的,它在程序刚开始运行和产生视图后被调用。然而,由于线程函数了的第一条语句就是调用WaitForSingleObject函数,线程立即挂起,等待线程启动的事件的信号。
当线程启动的事件被信号通知到,线程就可以显示它的消息框和进入循环,等待线程结束的事件。循环一直运行,直到线程结束的事件被信号通知到,这时,线程发送WM_THREADENDED消息到主程序,然后推出。由于线程是在OnCreate函数里启动的,因此,在线程结束后,它不可以被再次启动。