|
-
December 29th, 2011, 08:18 AM
#1
Best way to toggle between views
Hi all,
I have a Dialog project and I am loading a form view inside a frame:
Code:
int CMyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_pFrame = (CFrameWnd*)RUNTIME_CLASS(CFrameWnd)->CreateObject();
m_pFrame->CreateEx(0, NULL, NULL, WS_CHILD, rc, this, AFX_IDW_PANE_FIRST, NULL);
CCreateContext ccc;
ccc.m_pNewViewClass = RUNTIME_CLASS(CHtmlView);
ccc.m_pCurrentDoc = NULL;
ccc.m_pNewDocTemplate = NULL;
ccc.m_pLastView = NULL;
ccc.m_pCurrentFrame = NULL;
m_pMyFirstView = (CMyFirstView*)m_pFrame->CreateView(&ccc);
Everything works fine and I can load the view with no problems.
Now I want to toggle between two different views when a buttons is clicked.
So I've extended the code to:
Code:
int CMyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_pFrame = (CFrameWnd*)RUNTIME_CLASS(CFrameWnd)->CreateObject();
m_pFrame->CreateEx(0, NULL, NULL, WS_CHILD, rc, this, AFX_IDW_PANE_FIRST, NULL);
CCreateContext ccc;
ccc.m_pNewViewClass = RUNTIME_CLASS(CHtmlView);
ccc.m_pCurrentDoc = NULL;
ccc.m_pNewDocTemplate = NULL;
ccc.m_pLastView = NULL;
ccc.m_pCurrentFrame = NULL;
m_pMyFirstView = (CMyFirstView*)m_pFrame->CreateView(&ccc);
ccc.m_pNewViewClass = RUNTIME_CLASS(CNoEmailViewForm);
ccc.m_pCurrentDoc = NULL;
ccc.m_pNewDocTemplate = NULL;
ccc.m_pLastView = NULL;
ccc.m_pCurrentFrame = NULL;
m_pMySecondView = (CMySecondView*)m_pFrame->CreateView(&ccc);
}
void CMyDlg::OnBnClickedButton()
{
if (m_bFirst)
{
m_pMySecondView->ShowWindow(SW_SHOW);
m_pMyFirstView ->ShowWindow(SW_HIDE);
m_bFirst = FALSE;
}
else
{
m_pMySecondView->ShowWindow(SW_HIDE);
m_pMyFirstView ->ShowWindow(SW_SHOW);
m_bFirst = TRUE;
}
}
This again works BUT I'm not sure if this is the correct way to do it.
I have a feeling that I need to do something with m_pLastView (CCreateContext).
Any advice?
Thank you
This again
-
December 29th, 2011, 08:24 AM
#2
Re: Best way to toggle between views
 Originally Posted by Salvadoravi
Hi all,
I have a Dialog project and I am loading a form view inside a frame:
I stopped reading there. That sounds like a bad plan. While bucking the doc/view framework can be done, it isn't always easy and you should have a really good reason for doing it.
-
December 29th, 2011, 08:47 AM
#3
Re: Best way to toggle between views
Thanks GCDEF,
I'll take a step back.
The reason why I'm implementing it in the way I've described above is because I need to extend a fully mature dialog program that probably cannot be converted into a non dialog project (and if it somehow can I assume that it will take forever).
My Goal:
Code:
----------------------------------------------------------------
| Existings Dialog with loads of custom controls |
| |
| |
----------------------------------------------------------------
| | |
| [extensions] Adding a splitter | |
| | |
| to load the views | |
| | |
| | |
| (CHTMLEditView) | (CHTMLView) |
| | |
|---------------------------------------------------------------
Surprisingly it works fine.
My next step is to add functionality to load a single view as described in my above question.
Any advice will be appreciated!!
-
December 29th, 2011, 02:36 PM
#4
Re: Best way to toggle between views
 Originally Posted by Salvadoravi
... I need to extend a fully mature dialog program that probably cannot be converted into a non dialog project (and if it somehow can I assume that it will take forever).
There is no any "dialog program" that cannot be converted into a non dialog project. Period.
Victor Nijegorodov
-
December 29th, 2011, 03:20 PM
#5
Re: Best way to toggle between views
After the "Period" I would add "With enough people, time and money."
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|