CView and Forms
Does anyone know how to display a dialog/form in CView?
I need the basic application to be CView to display data from a data base, but also need data input screens, to allow the input of new data. While I can do this with modal dialogs, I would rather display the dialog/form in the CView display area, and not as a modal dialog.
thanks
[357 byte] By [
Darl444] at [2007-11-18 17:31:32]

# 3 Re: CView and Forms
I guess I wasn't fully clear on what I need.
I need to be able to reports, derived from the data in the data base in the CView display area, as well as, input dialogs/forms in the CView display area.
It seems it should be a very simple process, but I haven't had any luck with implementing it.
Just would like to know how to display the dialog/form in the client area of CView, via an OnDraw() or something similar.
Thanks for the previous replys
# 6 Re: CView and Forms
I've tried CFormView, and it is not what I want.
I have several different dialogs/forms to display to allow the user to input data into the database, but I also want the use the display area to display reports that I build from the database, which is easy to do using OnDraw() in CView.
I have implemented the above using Modal Dialog boxes to get the data into the database. I would just like to modify the CView program, to display the dialogs in the CView display area, and not as a popup dialog.
I just would like to know how to display the dialogs/forms in the same display area of the CView.
Thanks again for the quick replies
# 7 Re: CView and Forms
Probably CFormView or CRecordView would be the best solution. There are many articles around that describe how to use (one of) multiple views for a single document, which sounds like what you are trying to do. You can put a bitmap static control in each dialog for the reports. Then you can draw the reports using a memory device context and then set the control to the bitmap.
There is essentially not a client area of a view. We don't use that terminology for views at least. Technically speaking, the entire view is a client area.
An alternative is to create the controls dynamically in the view.
If you want to, try using my Child Dialogs (http://simplesamples.info/MFC/ChildDialogs.php) page. Although it is written as if a dialog will be a child of another dialog, it might be enough to help you to put your dialogs in a CView.
# 8 Re: CView and Forms
I think I figured it out, the best of both worlds.
I first created an SDI CView project. Then using a dialog editor, designed a test dialog, changing the default properties to child, and no border. Then using class wizard, created a class for the dialog, but changed the default base class to CFormView.
I then modified the menu, adding two items under View, to select either the orginal CView, or the CFormView. The message handlers for this new menu items were then placed in CMainFrame (MainFrm.cpp)
Much of the code below is not original, as I found two other example programs either here on dev-archive or on www.CodeProject.com site, though I don't have immediate access to the URLs.
Here's the example code:
void CMainFrame::SwitchViews(int nView)
{
//nView == 0, orginal view, nView == 1, testform
CView* pNewView;
CView* pOldView;
if(this->m_pOrgView == NULL)
m_pOrgView = this->GetActiveView();
pOldView = GetActiveView();
CCreateContext context;
context.m_pCurrentDoc = m_pOrgView->GetDocument();
switch(nView)
{
case 0: //original view
{
pNewView = m_pOrgView;
break;
}
case 1: // m_pFormView1
{
if(m_pTestForm == NULL) //need to create the form
{
m_pTestForm = new CTestForm;
m_pTestForm->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
this, IDD_TESTFORM, &context);
m_pTestForm->OnInitialUpdate();
}
pNewView = m_pTestForm;
break;
}
}
SetActiveView(pNewView);
pNewView->ShowWindow(SW_SHOW);
pOldView->ShowWindow(SW_HIDE);
pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
}
void CMainFrame::OnViewCform()
{
this->SwitchViews(1);
}
void CMainFrame::OnViewCview()
{
this->SwitchViews(0);
}
I want to thank everybody that previously responded to my original post.