细微区别:视图中GetParentFrame 和 AfxGetMainWnd

细微区别:视图中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成员。

你可能感兴趣的:(界面)