AfxGetMainWnd 与 theApp.GetMainWnd()

来源:互联网 发布:少年包青天3结局 知乎 编辑:程序博客网 时间:2024/05/22 02:35

一般情况下:

如果是主线程中应用:

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源码;

原创粉丝点击