AfxGetMainWnd 与 theApp.GetMainWnd()

一般情况下:

如果是主线程中应用:

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

你可能感兴趣的:(AfxGetMainWnd 与 theApp.GetMainWnd())