cpp9844
asked on
multiview problem ?
hi,all
i wrote a SDI app with outlook style UI:
it has several views,you may click the button in the left pane to switch to the corresponding view in the right pane.
i created all views(apart from the view created by MFC)when program began(in CMainFrame::OnCreateClint( ),for example),but i came across a problem when switching views:(i used Kirk Stowell's code)
BOOL CCJFlatSplitterWnd::Switch View(int nRow, int nCol, CView *pNewView)
{
CView *pOldView = DYNAMIC_DOWNCAST( CView,GetPane( nRow, nCol ));
ASSERT_KINDOF( CView, pOldView );
if( pOldView == pNewView )
return FALSE;
int nOldID, nNewID;
nOldID = pOldView->GetDlgCtrlID();
nNewID = pNewView->GetDlgCtrlID();
pOldView->SetDlgCtrlID(nNe wID);
VERIFY(pNewView->SetDlgCtr lID(nOldID ));
pOldView->ShowWindow(SW_HI DE);
pNewView->ShowWindow(SW_SH OW);
RecalcLayout();
return TRUE;
}
the method recalclayout() always goes wrong:
debug assertion failed!
file:winsplit.cpp
line:264
i think the problem is that the view to switch is not 'attached' to the right pane,is it right?
please help me!
thanks!!
i wrote a SDI app with outlook style UI:
it has several views,you may click the button in the left pane to switch to the corresponding view in the right pane.
i created all views(apart from the view created by MFC)when program began(in CMainFrame::OnCreateClint(
BOOL CCJFlatSplitterWnd::Switch
{
CView *pOldView = DYNAMIC_DOWNCAST( CView,GetPane( nRow, nCol ));
ASSERT_KINDOF( CView, pOldView );
if( pOldView == pNewView )
return FALSE;
int nOldID, nNewID;
nOldID = pOldView->GetDlgCtrlID();
nNewID = pNewView->GetDlgCtrlID();
pOldView->SetDlgCtrlID(nNe
VERIFY(pNewView->SetDlgCtr
pOldView->ShowWindow(SW_HI
pNewView->ShowWindow(SW_SH
RecalcLayout();
return TRUE;
}
the method recalclayout() always goes wrong:
debug assertion failed!
file:winsplit.cpp
line:264
i think the problem is that the view to switch is not 'attached' to the right pane,is it right?
please help me!
thanks!!
ASKER
Thank you,kirthir.
But your code can not solve my problem . In fact,i have
used similar code (from <<Inside Visual C++6.0>> )serval days before:it does not work.
Also,i need all views to be created when application begins ,that is,i will not need operation such as CREATE or DESTROY when switching them .it is so-called static switch.
another means do you have? Thanks!!
But your code can not solve my problem . In fact,i have
used similar code (from <<Inside Visual C++6.0>> )serval days before:it does not work.
Also,i need all views to be created when application begins ,that is,i will not need operation such as CREATE or DESTROY when switching them .it is so-called static switch.
another means do you have? Thanks!!
Did you tried static splitter windows?
ASKER
of course,the whole client area is splited to two panes.
the left is control area,the right is display area,just like outlool
the left is control area,the right is display area,just like outlool
If you are using Static splitter windows, what is the necessary of writing code for changing views, it will be automatically taken care know.
Did you follow the same approach for creating two views?
1)Create an SDI application
2)Create a new view class from classwizard
3)Copy the GetDocument() implementation from the original view created by appwizard
4)Include the following code in the OnCreateClient of mainfrm file
VERIFY(m_wndSplitter.Creat eStatic(th is,2,1));
VERIFY(m_wndSplitter.Creat eView(0,0, RUNTIME_CL ASS(CStati cSplitterV iew),CSize (100,100), pContext)) ;
VERIFY(m_wndSplitter.Creat eView(1,0, RUNTIME_CL ASS(CStati cSplitterV iew1),CSiz e(100,100) ,pContext) );
5)In both the views, implement whatever you want - for changing the view context you can just click on the required view, you are there
Why u want to put a button to switch to other view
Let me know
Did you follow the same approach for creating two views?
1)Create an SDI application
2)Create a new view class from classwizard
3)Copy the GetDocument() implementation from the original view created by appwizard
4)Include the following code in the OnCreateClient of mainfrm file
VERIFY(m_wndSplitter.Creat
VERIFY(m_wndSplitter.Creat
VERIFY(m_wndSplitter.Creat
5)In both the views, implement whatever you want - for changing the view context you can just click on the required view, you are there
Why u want to put a button to switch to other view
Let me know
ASKER
OK,i just want to write it to monitor a system.
there are different kinds of parameters to mon,you know.
so you may click the buttons in the left pane(like MS outlook express!)to switch to diffent views to mon different params.
it is so convient for our users!
by the way,i have implement 'dynamic switch '---first
create new view then destroy old view when switch,
but the effect is not so good ,
so i need a 'static switch' implementation
there are different kinds of parameters to mon,you know.
so you may click the buttons in the left pane(like MS outlook express!)to switch to diffent views to mon different params.
it is so convient for our users!
by the way,i have implement 'dynamic switch '---first
create new view then destroy old view when switch,
but the effect is not so good ,
so i need a 'static switch' implementation
As per my understanding goes,
1)You want to have two views, one on the left and one on the right
2)You want to have buttons on the left pane
First assumption
3)Assuming you have 3 buttons on left side
IF you click button1 you want to display something like for example printing some text and if you click button2 you want to display some graphic object
for eg:- button1 click results in printing of "hello world"
on the right side view and button2 click results in displaying a graphic object like bitmap
If this is the case, two views are sufficient and it is easy to implement
Second assumption
4)If you have 3 different views associated with 3 button clicks, you need to get the corresponding view on board immediately when the button gets clicked
Let me know which of these two things you are looking at
1)You want to have two views, one on the left and one on the right
2)You want to have buttons on the left pane
First assumption
3)Assuming you have 3 buttons on left side
IF you click button1 you want to display something like for example printing some text and if you click button2 you want to display some graphic object
for eg:- button1 click results in printing of "hello world"
on the right side view and button2 click results in displaying a graphic object like bitmap
If this is the case, two views are sufficient and it is easy to implement
Second assumption
4)If you have 3 different views associated with 3 button clicks, you need to get the corresponding view on board immediately when the button gets clicked
Let me know which of these two things you are looking at
Send me correctly what you want to achieve
clear specs, then I can think of giving a solution
clear specs, then I can think of giving a solution
ASKER
ah!
i think your understanding is same with mine!:)
but in my view,the situation that 2,3 or more views in one pane(the right pane) and their corresponding button (in the left pane)is similar!
users decide the number of views,you know.
Do you see my first post?
all my views are created when app begin,stored in a array:CView* m_pViews[MAX_VIEWS],a member var of CMainFrame
i think your understanding is same with mine!:)
but in my view,the situation that 2,3 or more views in one pane(the right pane) and their corresponding button (in the left pane)is similar!
users decide the number of views,you know.
Do you see my first post?
all my views are created when app begin,stored in a array:CView* m_pViews[MAX_VIEWS],a member var of CMainFrame
ASKER
i feel like...
ASKER
who can help me?????
Please give a step-by-step information about ur requirement such that I can try to help you (don't miss out anything)
ASKER
thanks ,kirthir !
i have solved it!!
in fact it is very easy.
Please check my first post,and add one line in SwitchView():
pNewActiveView->SetParent( this);
what i have doubted is really the case! the view to switch is not 'attached' with the right pane,and this pane
is managed by splitterWnd.
the code added solves it!
thanks again for your help!!!
i have solved it!!
in fact it is very easy.
Please check my first post,and add one line in SwitchView():
pNewActiveView->SetParent(
what i have doubted is really the case! the view to switch is not 'attached' with the right pane,and this pane
is managed by splitterWnd.
the code added solves it!
thanks again for your help!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I defined this in mainfrm.h
enum eView{GRAPHIC=1, TEXT=2};
and implemented SwitchToView in Mainfrm.cpp
void CMainFrame::SwitchToView(e
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = (CView*)GetDlgItem(nView);
if (pNewActiveView == NULL)
{
switch(nView)
{
case TEXT:
pNewActiveView = (CView*) new CSDIMultipleViewsView;
break;
case GRAPHIC:
pNewActiveView = (CView*) new CTextView;
break;
}
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocumen
pNewActiveView->Create(NUL
pNewActiveView->OnInitialU
}
SetActiveView(pNewActiveVi
pNewActiveView->ShowWindow
pOldActiveView->ShowWindow
pOldActiveView->SetDlgCtrl
pNewActiveView->SetDlgCtrl
RecalcLayout();
}
Hope this helps