切换视图的核心代码
_AFXCORE_INLINE BOOL AfxSwitchToStaticView( CRuntimeClass * pViewClass )
{
CNineDoc * pNineDoc = AfxGetStaticDoc();
BOOL bOK = pNineDoc->ShowStaticView( pViewClass );
CView * pView = pNineDoc->GetViewIfExist( pViewClass );
if( pView )
pView->SetFocus( );
return bOK;
}
CWnd* CWnd::SetFocus()
{
//判断句柄是否有效
ASSERT(::IsWindow(m_hWnd));
// CWnd::FromHandle——根据窗口句柄得到CWnd*指针
return CWnd::FromHandle(::SetFocus(m_hWnd));
}
策略
// 策略改动之后,刷新视图
_AFXCORE_INLINE void AfxOnStrategyUpdated( CStrategy * pStrategy, BOOL bReRealRun )
{
CStrategyView * pStrategyView = AfxGetStrategyView();
if( pStrategyView )
发送消息用户自定义消息WM_USER_UPDATESTRATEGY,此时会调用OnUpdateStrategy函数。
pStrategyView->SendMessage( WM_USER_UPDATESTRATEGY, DWORD(pStrategy) );
//获得文档对象,并更新所有视图
CNineDoc * pNineDoc = AfxGetStaticDoc();
if( pNineDoc )
{
文档更新视图
问题 二、三个文档更新视图的函数,虽然传入参数不同,但是他们有区别吗 ?
pNineDoc->UpdateAllViews( NULL, UPDATE_HINT_NINEVIEW, NULL );
if( bReRealRun )
pNineDoc->UpdateAllViews( NULL, UPDATE_HINT_SIMUVIEW_REREALRUN, NULL );
else
pNineDoc->UpdateAllViews( NULL, UPDATE_HINT_SIMUVIEW, NULL );
}
}
得到策略视图对象
CStrategyView * AfxGetStrategyView( )
{
CStrategyView * pView = NULL;
CMainFrame * pFrame = AfxGetMainFrame();
if( pFrame )
pView = DYNAMIC_DOWNCAST(CStrategyView,pFrame->GetStrategyView( ) );
return pView;
}
通过传入参数wParam 来更新策略
LRESULT CStrategyView::OnUpdateStrategy(WPARAM wParam, LPARAM lParam)
{
CStrategy * pStrategy = (CStrategy *)wParam;
UpdateStrategy( pStrategy );
return 0;
}