现在的位置: 首页 > 综合 > 正文

AfxGetMainWnd 与 theApp.GetMainWnd()

2013年11月12日 ⁄ 综合 ⁄ 共 433字 ⁄ 字号 评论关闭

一般情况下:

如果是主线程中应用:

1:对话框程序,获取的是主窗口;

2:文档程序获取的是主框架;

AfxGetMainWnd  与 theApp.GetMainWnd()没有什么区别;

但是在辅助线程中应用,就有区别:

If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main
window associated with the thread that made the call.

也就是说AfxGetMainWnd在一般的辅助线程中应为没有界面,所以返回NULL;

这是可以通过theApp.GetMainWnd()获取主界面,这具体可参考MFC源码;

抱歉!评论已关闭.