SDI multiview SW_SHOWMAXIMIZED problem

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
I am working on a SDI application which has multiple views. The application is initially maximized. If I switch the views by selecting from menu or toolbar, the view can be switched and the maximized display works fine. However, when I finish handling a
view and would like to close it and switch to the default one by sending a message to the mainframe, the display can not show maximized, but the size of the default view at design stage, even if I add ShowWindow(SW_SHOWMAXIMIZED) in the switchview function.
I tried adding
ShowWindow(SW_HIDE);<br/>
ShowWindow(SW_SHOWMAXIMIZED);<br/>
ShowWindow(SW_SHOW);
in the swithview function, it can now be maximized, but only with flickering. So would anyone please suggest how I should do to switch from one view to the default one, keeping the frame maximized while avoiding flickering problem? Below are
some codes I used.
<div style="color:Black;background-color:White; <pre>
BOOL CMainFrame::SwitchView(CRuntimeClass* pNewViewClass)
{
CView* pOldView = GetActiveView();

<span style="color:Green; // If no active view for the frame, return FALSE because
<span style="color:Green; // this function retrieves the current document from the active
<span style="color:Green; // view.
<span style="color:Blue; if (pOldView == NULL)
<span style="color:Blue; return FALSE;

<span style="color:Green; // If were already displaying this kind of view, no need
<span style="color:Green; // to go further.
<span style="color:Blue; if ((pOldView->IsKindOf(pNewViewClass))==TRUE)
<span style="color:Blue; return TRUE;

<span style="color:Green; // Get pointer to CDocument object so that it can be used
<span style="color:Green; // in the creation process of the new view.
CDocument * pDoc= pOldView->GetDocument();

<span style="color:Green; // Set flag so that document will not be deleted when
<span style="color:Green; // view is destroyed.
BOOL bAutoDelete=pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete=FALSE;
<span style="color:Green; // hide existing view
pOldView->ShowWindow(SW_HIDE);

<span style="color:Green; // restore flag
pDoc->m_bAutoDelete=bAutoDelete;


CCreateContext context;

<span style="color:Green; // Create new view and redraw.
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = pDoc;

CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context)); <span style="color:Green; // Now we can create a new view and get rid of the previous one

<span style="color:Blue; if (pNewView == NULL)
{
TRACE1(<span style="color:#A31515; "Warning: Dynamic create of view type %Fs failedn", pNewViewClass->m_lpszClassName);
<span style="color:Blue; return FALSE;
}

<span style="color:Blue; if( pNewView != NULL )
{
pNewView->ShowWindow(SW_SHOW);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
RecalcLayout();
}

<span style="color:Green; // Delete existing view
pOldView->DestroyWindow();

ShowWindow(SW_HIDE); <span style="color:Green; //to do this will cause flickering
ShowWindow(SW_SHOWMAXIMIZED);
ShowWindow(SW_SHOW);

<span style="color:Blue; return TRUE;
}

<span style="color:Green; //after handling a view, use message to inform mainframe to switch to default view


<span style="color:Blue; void CViewProductGroup::OnBnClickedOk()
{
<span style="color:Green; // TODO: Add your control notification handler code here
AfxGetMainWnd()->PostMessage(UWM_GROUP_VIEW_EXIT, (WPARAM)0, (LPARAM)0);
}

<span style="color:Green; //in mainframe message UWM_GROUP_VIEW_EXIT will be handled

LONG CMainFrame::OnGroupViewExit(UINT wP, LONG lP)
{
SwitchView(RUNTIME_CLASS(CIMTView)); <span style="color:Green; //the default view

<span style="color:Blue; return 0;
}
[/code]
<hr class="sig I am new to VC++ programming, but I am passionate about it

View the full article
 
Back
Top