This is a part of the Microsoft Foundation Classes C++ library.
Copyright (C) 1994-1998 Microsoft Corporation
All rights reserved.
This source code is only intended as a supplement to the
Microsoft Foundation Classes Reference and related
electronic documentation provided with the library.
See these sources for detailed information regarding the
Microsoft Foundation Classes product.
-------------------------------------------------------
MTMDI Sample Microsoft Foundation Classes Application
-------------------------------------------------------
The MTMDI sample illustrates an MFC user-interface thread, where user
interface events are processed in a thread separate from the main
application thread. This sample is a modified version of the single
thread MDI sample.
The MTMDI sample does not claim a strong rationale for putting the
bouncing ball window in a separate thread. An end-user would not be
able to detect the difference between the MDI and MTMDI samples on a
single processor machine. Even on a multi-processor machine, the
end-user would not be able to detect the difference given that the
ball movement is based on a window timer.
Further, the MTMDI sample does not claim a strong rationale for using
an MFC worker thread instead of an MFC user-interface thread. MFC worker
threads generally are easier to use and more appropriate than user-interface
threads for tasks that do not involve processing of user interface events.
The drawing of the bouncing ball could have been implemented in
a worker thread instead of a user-interface thread, if some technique
other than window timers were used to advance the ball. The use of the
window timer in a separate thread requires a message pump; therefore
the separate thread must be a user-interface thread instead of a worker
thread. To add slightly more justification for using a user-interface
thread, the MTMDI sample includes one additional user-interface feature
not in the MDI sample: you can click anywhere in the bounce window to
immediately change the position of the moving ball.
Although the MDI sample does not claim a strong rationale for using
threads, it nevertheless does illustrate techniques for implementing an
MFC user-interface thread. The remainder of this readme describes
the differences between the implementation of the single thread MDI
application and the multiple thread MTMDI application. These differences
illustrate that it is more difficult to implement an application with
a user-interface thread than a corresponding application that executes
in a single thread. This should be a warning that you should not use
user-interface threads unless you have good reasons.
The overall differences between the implementation of the MDI and MTMDI
samples are these:
1. The CBounceWnd window runs in a separate user-interface thread
in the MTMDI application.
2. In the MDI sample, CBounceWnd is derived from CMDIChildWnd. In the
MTMDI sample, CBounceWnd is derived from CWnd, and a CBounceWnd
window is a child of the MDI child window. In the MTMDI sample,
the CBounceWnd child window fills exactly the client area of the
parent MDI child window (a CMDIChildBounceWnd).
3. In the MDI sample, normal MFC command routing and command user-
interface initialization are used for menu commands associated with
the bounce window. In the MTMDI sample, the MDI child window's
OnCmdMsg function is overridden in order to send the OnCmdMsg
parameters via SendMessage to the CBounceWnd executing in the
separate thread. In general, SendMessage typically needs to be
used us to make calls from a window in one thread to a window in
another thread in an MFC application.
Note: The Hello window is left in the main application thread.
Implementing the Bounce window in a separate thread is sufficient
to illustrate the MFC multithread techniques.
This MTMDI sample does not directly illustrate a view running in a separate
thread, because MTMDI and the original MDI sample do not use MFC's
document/view architecture. Still, the design of MTMDI can be applied
to an application where you might want the view to run in a separate thread.
In general, you cannot successfully implement member functions of a CView
to run in a separate thread, because the MFC document/view architecture
relies on thread local storage (TLC) for some of the data that coordinates
documents and views. However, you can apply the design of MTMDI by
implementing a child window of the CView window, and processing user-
interface events of this child window in a separate thread.
The design of MTMDI is summarized below. For additional details, see
source code comments.
=================
CWinThread object
=================
The thread object for the bouncing ball window is implemented in
a CWinThread-derived class, CBounceThread, in mtbounce.cpp.
Beginning the user-interface thread
-----------------------------------
The overridden CMDIChildBounceWnd::OnCreate begins the thread for
the bouncing ball. There are two ways to begin an MFC user-interface
thread: (1) call AfxBeginThread, passing the CRuntimeClass of the
CWinThread-derived class; or (2) implement two-stage construction of
the CWinThread-derived object by new'ing it and then calling
CWinThread::CreateThread. We use the second method because it offers
the easiest way to pass the HWND of the CMainFrame window to the
thread, which needs the parent HWND to create the child window.
We simply pass the HWND to the CBounceThread constructor.
An alternative method is:
- call AfxBeginThread with a CREATE_SUSPENDED parameter;
- pass the parent HWND via a new CBounceThread::SetParentWnd function;
or make the CBounceThread::m_hwndParent member variable public and
set it directly; and then
- call CWinThread::ResumeThread.
Thread instance initialization
------------------------------
CWinThread::InitInstance is the only member function that must be
overridden for a user-interface thread. The implementation of
CBounceThread::InitInstance is typical in that it creates (using
CWnd::Create) the window that processes messages in the separate thread.
Terminating the user-interface thread
-------------------------------------
The easiest way to terminate a user-interface thread is to rely on
automatic termination of the thread when the main window associated with
the thread is destroyed. The only thing you need to do to implement
such automatic thread termination is to set the CWinThread::m_pMainWnd
to the main window. This is illustrated in CBounceThread::InitInstance.
The default CWnd::OnNcDestroy handler checks whether the window being
destroyed is the thread's m_pMainWnd and, if so, terminates the thread,
provided it isn't the main application thread.
Unless you change the default TRUE value of CWinThread::m_bAutoDelete,
the framework will automatically delete the CWinThread object when the
thread terminates.
Avoiding memory leak detection of CWinThread object
---------------------------------------------------
When the application terminates, it destroys each window in the window
hierarchy, and then, in debug mode, checks for memory leaks.
It is possible that the application will falsely detect a memory leak of the
CWinThread object before the user-interface thread has had a chance to
automatically terminate. The reported memory leak is false because
eventually the CWinThread object will be automatically destroyed anyway.
Nevertheless, the dumping of memory leak information can be disconcerting.
To avoid this, we use a "bounce thread killed" event. The CBounceThread
delete operator sets the event. The main application waits for this event
before terminating. It is better to set the event in the delete operator
rather than in the CBounceThread destructor, because it is remotely possible
that the applicati
没有合适的资源?快使用搜索试试~ 我知道了~
无线视频监控源码
共101个文件
h:28个
cpp:23个
ico:16个
4星 · 超过85%的资源 需积分: 0 46 下载量 64 浏览量
2008-07-31
11:27:07
上传
评论 2
收藏 901KB RAR 举报
温馨提示
对搞视频监控的人有很大帮助,希望对您有用
资源推荐
资源详情
资源评论
收起资源包目录
无线视频监控源码 (101个子文件)
play.aps 46KB
MtMdi.aps 36KB
Toolbar.bmp 838B
PLAY.CLW 4KB
Mtmdi.clw 3KB
playView.cpp 25KB
revplaymdichildwnd.cpp 24KB
MPGUTIL.CPP 21KB
Asyncio.cpp 17KB
PLAY.CPP 12KB
Asyncrdr.cpp 10KB
MainFrm.cpp 9KB
VideoPlay.cpp 8KB
AV8Buffer.cpp 4KB
asyncflt.cpp 4KB
MDI.CPP 3KB
MAINFRM.CPP 3KB
ModifyPwd.cpp 3KB
SetPwd.cpp 2KB
InputPwd.cpp 2KB
RevPlayThread.cpp 2KB
playDoc.cpp 2KB
RevMDIChildWnd.cpp 1KB
StopModeDlg.cpp 1KB
ConnectDlg.cpp 1KB
WaitDlg.cpp 976B
STDAFX.CPP 628B
StdAfx.cpp 206B
Thumbs.db 22KB
mtmdi.dsp 8KB
play.dsp 7KB
ModifyPwd.dsp 3KB
MTMDI.DSW 533B
PLAY.DSW 531B
ModifyPwd.dsw 520B
AV8api.h 17KB
ASYNCIO.H 8KB
ASYNCRDR.H 7KB
asyncflt.h 6KB
MPGUTIL.H 6KB
revplaymdichildwnd.h 5KB
playView.h 4KB
RESOURCE.H 3KB
DEFINE.H 3KB
MPEGDEF.H 3KB
MainFrm.h 3KB
VideoPlay.h 2KB
PLAY.H 2KB
RevPlayThread.h 2KB
playDoc.h 1KB
RevMDIChildWnd.h 1KB
ModifyPwd.h 1KB
StopModeDlg.h 1KB
ConnectDlg.h 1KB
InputPwd.h 1KB
WaitDlg.h 1KB
AV8Buffer.h 1KB
SetPwd.h 1KB
RESOURCE.H 1KB
StdAfx.h 1KB
STDAFX.H 1KB
MDI.H 789B
MAINFRM.H 679B
AMCAP.ICO 1KB
Foldrs02.ico 1KB
PLAY.ICO 1KB
Audio.ico 1KB
Note16.ico 1KB
Cdrom01.ico 1KB
playDoc.ico 1KB
Openfold.ico 1KB
Trffc14.ico 1KB
HELLO.ICO 766B
MDI.ICO 766B
ICON11.ICO 766B
ICON9.ICO 766B
ICON12.ICO 766B
ICON10.ICO 766B
Camera.ico 766B
strmbasd.lib 1.8MB
CJ608Libd.lib 523KB
CJ608Lib.lib 514KB
asynbase.lib 124KB
asyncflt.lib 2KB
MTMDI.MAK 10KB
MAKEFILE 514B
PLAY.NCB 649KB
MTMDI.NCB 561KB
Play.opt 71KB
MTMDI.opt 65KB
ModifyPwd.opt 37KB
PLAY.PLG 2KB
MTMDI.PLG 1KB
ModifyPwd.plg 748B
play.rc 15KB
MtMdi.rc 6KB
PLAY.RC2 396B
README.TXT 11KB
ReadMe.txt 4KB
www.pudn.com.txt 218B
共 101 条
- 1
- 2
资源评论
- jnpher2012-06-20有些代码是放在lib库里面的,如果能一起共享就好了。还是不错。
- wbybyb2011-12-22有些代码是放在lib库里面的,如果能一起共享就好了。还是不错。谢谢。
- nihaoma100002011-12-17windows 下的 没有解释。。
- drzhello2013-05-07代码是不错 不过没注释 没怎么可以进行扩展
- Atering2011-12-05只有代码,而且没有任何说明,需要的硬件环境也不匹配
取证
- 粉丝: 1
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 全卷积网络基于voc2012数据集简单pytorch实现
- pycharm的一些介绍-用于更好的学习python
- 基于C++的程序设计大赛天梯赛L2答案(天梯赛)
- 基于python实现的三次样条插值和均值插值法实现
- Python语言教程2-python批量图片大小处理-多文件夹
- Python语言教程1-python批量图片重命名,将后缀某几个不想要的字去除
- Space Combat Kit 太空战斗套件Unity游戏开发插件资源unitypackage C#
- Universal Device Preview 通用设备预览Unity游戏开发插件资源unitypackage
- Paladin Anim Set 圣骑士动画集Unity游戏动作动画插件资源unitypackage
- 计算机财务管理期末考报表部分题目及答案.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功