CWinThread::m_pMainWnd
来源:互联网 发布:java 文件md5校验码 编辑:程序博客网 时间:2024/05/01 23:23
CWinThread::m_pMainWnd
Use this data member to store a pointer to your thread’s main window object. The Microsoft Foundation Class Library will automatically terminate your thread when the window referred to bym_pMainWnd is closed. If this thread is the primary thread for an application, the application will also be terminated. If this data member isNULL, the main window for the application’s CWinApp object will be used to determine when to terminate the thread.m_pMainWnd is a public variable of type CWnd*.
Typically, you set this member variable when you override InitInstance. In a worker thread, the value of this data member is inherited from its parent thread.
forlike:
BOOL CSheetTestApp::InitInstance()
{
..................................//去除模态窗口的创建,自己添加非模态窗口
CSheetTestDlg *p=new CSheetTestDlg();
m_pMainWnd=p;
p->Create(IDD_SHEETTEST_DIALOG);
p->ShowWindow(SW_HIDE);
return TRUE;
}
用该成员变量去存储你的线程主窗口对象。当和m_pMainWnd 相关的窗口被关闭后,MFC会自动终止你的线程。如果该线程是应用程序主线程,程序也将会被终止。如果该数据成员为NULL,应用程序CWinApp对象的主窗口将用来决定什么时候去终止线程。m_pMainWnd是一个CWnd*类型的public变量。
很明显,你需要在重载InitInstance时为m_pMainWnd赋值。在工作线程中,m_pMainWnd自动继承其父线程的值。
补充:只有CWinThread对象才有m_pMainWnd
class CWinThread : public CCmdTarget
{
DECLARE_DYNAMIC(CWinThread)
public:
// Constructors
CWinThread();
BOOL CreateThread(DWORD dwCreateFlags = 0, UINT nStackSize = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);
// Attributes
CWnd* m_pMainWnd; // main window (usually same AfxGetApp()->m_pMainWnd)
CWnd* m_pActiveWnd; // active main window (may not be m_pMainWnd)
BOOL m_bAutoDelete; // enables 'delete this' after thread termination
..............
}
//在用户界面线程中创建非模态对话框
if (!pDlg.Create(IDD_DIALOG1, NULL))
{
AfxMessageBox("窗口创建失败!");
}
else
{
pDlg.ShowWindow(SW_SHOW);
m_pMainWnd=&pDlg;
}
在创建用户界面线程时,该句一定要加上。否则在线程不会得到释放
转载自:http://hi.baidu.com/hj11yc/item/8c9232094968e33d4ac4a388
- CWinThread::m_pMainWnd
- CWinThread::m_pMainWnd
- m_pMainWnd
- CWinThread
- CWinThread
- CWinThread
- CWinThread
- 关于m_pMainWnd
- AfxGetApp()->m_pMainWnd
- MFC - m_pMainWnd
- MFC - m_pMainWnd
- CWinThread类
- CWinThread::ExitInstance
- CWinThread删除
- MFC-CWinThread
- CWinThread 结束
- m_pMainWnd的由来
- 主窗口变量 m_pMainWnd
- Android程序连接Delphi DataSnap服务器
- 收藏的网页--素材资料下载(free)
- 从Hello World中了解程序的运行过程
- Eclipse 不能自动编译
- PHP内核探索:zend_parse_parameters函数
- CWinThread::m_pMainWnd
- Windows 7下搭建本地Discuz论坛
- 一些好的习惯《1-30条》--NALA CEO
- 鸣人的查克拉
- xcode4的环境变量,Build Settings参数,workspace及联编设置
- 全分布式下安装hbase(使用hbase自带的zookeeper)
- HBASE SHELL 常用命令
- jasperreport+ireport
- 基于 IO密集 & CPU密集考量 SAN & NAS 选择的一点建议