具有多个视图活动的SDI应用程序 [英] SDI application with multiple views active
问题描述
我正在创建一个示例学习应用程序,以便在SDI中同时创建多个活动视图。我面临的问题是,虽然我在第二个视图类中覆盖了OnDraw,但我对SetModifiedFlag(true)和UpdateAllViews()的调用并没有调用第二个视图OnDraw()。我调试到UpdateAllviews,我可以看到我的第二个视图的OnUpdate被成功调用所有参数0.我错过了什么?请任何人帮忙
代码看起来像这样
CMainWnd :: CMainWnd()
{
m_pSecondWnd = new CSecondaryWnd();
m_pSecondWnd->创建(0,L第二窗口,WS_OVERLAPPEDWINDOW);
}
void CMainWnd :: CreateNewView(CRuntimeClass * pView,CFrameWnd * pNewWnd,UINT ID)
{
CView * pNewView = NULL;
pNewView =(CView *)pView-> CreateObject();
CCreateContext上下文;
context.m_pCurrentDoc = GetActiveDocument();
pNewView->创建(0,0,AFX_WS_DEFAULT_VIEW,rectDefault,pNewWnd,1,& context);
pNewView-> OnInitialUpdate();
((CSecondaryWnd *)pNewWnd) - > ShowWindow(SW_RESTORE);
pNewView-> ShowWindow(SW_RESTORE);
pNewWnd-> UpdateWindow();
}
void CMainWnd :: OnTimer(UINT_PTR nIDEvent)
{
switch(nIDEvent)
{
case ONE_SECOND_TIMER:
{
CSampleDocument * pDoc =(CSampleDocument *)GetActiveDocument();
pDoc-> SetModifiedFlag();
pDoc-> UpdateAllViews(NULL);
// Invalidate();小道
休息;
}
}
}
示例视图2类:
IMPLEMENT_DYNCREATE(CSampleView2,CView)
BEGIN_MESSAGE_MAP(CSampleView2,CView)
END_MESSAGE_MAP()
CSampleView2 :: CSampleView2()
{
}
CSampleView2 :: ~CSampleView2 ()
{
}
void CSampleView2 :: OnDraw(CDC * pDc)
{
int a = 10;
pDc-> TextOut(100,100,LThis,5);
}
示例视图1类:
IMPLEMENT_DYNCREATE(CSampleView1,CView)
BEGIN_MESSAGE_MAP(CSampleView1,CView)
ON_COMMAND(ID_VIEW_CREATE,OnViewCreate)
END_MESSAGE_MAP()
CSampleView1 :: CSampleView1()
{
}
CSampleView1 :: ~CSampleView1 ()
{
}
无效CSampleView1 :: OnDraw(CDC * pDc)
{
pDc-> TextOut(100,100,L 这,5); int a = 10;
}
我的尝试:
调试UpdateAllView,我可以看到在循环浏览不同的视图时,我的第二个视图calss和OnUpdate被成功调用。
参见< a href =https://msdn.microsoft.com/en-us/library/eys41xfw(v=vs.80).aspx> CDocument :: UpdateAllViews(MFC) [ ^ ]以获取正确的更新方法视图。
Hi,
I am creating an sample learning application to create multiple active views at the same time in an SDI. The problem that i am facing is, though i have overridden the OnDraw in my second view class, my call to the SetModifiedFlag(true) and UpdateAllViews(), is not invoking the second views OnDraw(). I debugged into the UpdateAllviews and i could see my second view's OnUpdate is getting called successfully with all parameters 0. What is it that i am missing? please can any one help
Code looks something like this
CMainWnd::CMainWnd() { m_pSecondWnd = new CSecondaryWnd(); m_pSecondWnd->Create( 0, L"Second Window", WS_OVERLAPPEDWINDOW ); } void CMainWnd::CreateNewView( CRuntimeClass* pView, CFrameWnd* pNewWnd, UINT ID) { CView* pNewView = NULL; pNewView = (CView*)pView->CreateObject(); CCreateContext context; context.m_pCurrentDoc = GetActiveDocument(); pNewView->Create( 0, 0, AFX_WS_DEFAULT_VIEW, rectDefault, pNewWnd, 1 , &context ); pNewView->OnInitialUpdate(); ((CSecondaryWnd*)pNewWnd)->ShowWindow( SW_RESTORE ); pNewView->ShowWindow( SW_RESTORE ); pNewWnd->UpdateWindow(); } void CMainWnd::OnTimer( UINT_PTR nIDEvent ) { switch(nIDEvent) { case ONE_SECOND_TIMER: { CSampleDocument* pDoc = (CSampleDocument*)GetActiveDocument(); pDoc->SetModifiedFlag(); pDoc->UpdateAllViews( NULL ); //Invalidate(); trail break; } } } Sample View 2 class: IMPLEMENT_DYNCREATE( CSampleView2, CView ) BEGIN_MESSAGE_MAP( CSampleView2, CView ) END_MESSAGE_MAP() CSampleView2::CSampleView2() { } CSampleView2::~CSampleView2() { } void CSampleView2::OnDraw( CDC* pDc ) { int a = 10; pDc->TextOut( 100, 100, L"This", 5 ); } Sample View 1 Class: IMPLEMENT_DYNCREATE( CSampleView1, CView ) BEGIN_MESSAGE_MAP( CSampleView1, CView ) ON_COMMAND( ID_VIEW_CREATE, OnViewCreate ) END_MESSAGE_MAP() CSampleView1::CSampleView1() { } CSampleView1::~CSampleView1() { } void CSampleView1::OnDraw( CDC* pDc ) { pDc->TextOut( 100, 100, L"This", 5 );int a = 10; }
What I have tried:
Debugged UpdateAllView and i could see while looping through the different views, my second view calss and it OnUpdate is getting called successfully.
See CDocument::UpdateAllViews (MFC)[^] for the correct method of updating views.
这篇关于具有多个视图活动的SDI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!