细微区别:视图中GetParentFrame 和 AfxGetMainWnd.
下面代码:
// ((CMainFrame*)GetParentFrame())->SetStatusBarPositionText(12, 122);
// CMainFrame* pMainFrame= (CMainFrame*)( AfxGetApp()->m_pMainWnd);
CMainFrame* pMainFrame= (CMainFrame*)AfxGetMainWnd();
pMainFrame->m_wndStatusBar.SetPaneText(2,"abc");
// ((CMainFrame*)GetParentFrame())->m_wndStatusBar.SetPaneText(2,"abc");
如果用GetParentFrame一直不能得到statusbar.究其原因,GetParentFrame返回CWnd*,而这个指针指向CFrameWnd对象,而不是我们的CMainFrame对象,只有CMainFrame中才有statusbar成员。
博客介绍了视图中GetParentFrame和AfxGetMainWnd的细微区别。通过代码展示使用情况,指出用GetParentFrame一直无法得到statusbar,原因是其返回的指针指向CFrameWnd对象,而非有statusbar成员的CMainFrame对象。
1903

被折叠的 条评论
为什么被折叠?



