![]() |
Desktop Development »
Document / View »
Form Views
Intermediate
Inserting a Doc/Frame/View in a dialog using a custom controlBy Jean-Louis GuenegoA custom control allowing to insert a doc/view/frame architecture in a dialog/formview |
VC6, Windows, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

MFC architecture is often based on Doc/View/Frame architecture. Sometimes, it may be useful to have a doc/view/frame architecture in a dialog frame, or a formview. For example, if we want to edit a file (text, image, table, ...) in a dialog, or whatever. The set of class presented here can be useful.
For the time being, I never seen a such architecture, it is why I decided to implement it. If you have to use it and have a bit of time, please add a comment at the bottom of this page and tell in which context you decided to use this code. I would be interested.
The class CDFVCtrl is a custom control. Its Create Method takes the following information:
The custom control create a document template (CDFVDocTemplate). That allows us to benefit all the MFC implementation. Some of this implementation had to be reimplemented in order to satisfy our need. That's why we have the following class:
CDFVDocument (base class: CDocument)
CDFVFrameWnd (base class: CFrameWnd)
CDFVDocTemplate (base class: CSingleDocTemplate) Files needed:
Of course, you need to have Doc/Frame/View classes. In the demo project, these classes are called:
CSampleDoc/CMainFrame/CSampleView (I simply created a SDI project named "Sample") PICTURE control on it (this method to create custom control is - I think - the simplest way to create a custom control)

For each picture control, uncheck the "visible" style, and name these control IDC_DFVCTRL1, IDC_DFVCTRL2, IDC_DFVCTRL3, ...

CSampleDialog).
ONCOMMAND line : ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
InitInstance Method, remove the DocTemplate instructions, and the others following instructions. Add the initialization dialog instructions. You should have something like : BOOL CSampleApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSampleDialog Dlg;
Dlg.DoModal();
return TRUE;
}
(of course, #include "SampleDialog.h")
CSampleDialog), #include "DFVCtrl.h" and add the following attributes: CDFVCtrl m_DFVCtrl1, m_DFVCtrl2, m_DFVCtrl3;
(corresponding to the quantity of DFV control you want to add)
InitDialog method for the dialog and add the following code: BOOL CSampleDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_DFVCtrl1.Create(this, IDC_DFVCTRL1,
IDR_MAINFRAME,
RUNTIME_CLASS(CSampleDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSampleView),
WS_CHILD | WS_BORDER | WS_VISIBLE, 0L);
m_DFVCtrl2.Create(this, IDC_DFVCTRL2,
IDR_MAINFRAME,
RUNTIME_CLASS(CSampleDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSampleView),
WS_CHILD | WS_BORDER | WS_VISIBLE, 0L);
m_DFVCtrl3.Create(this, IDC_DFVCTRL3,
IDR_MAINFRAME,
RUNTIME_CLASS(CSampleDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSampleView),
WS_CHILD | WS_BORDER | WS_VISIBLE, 0L);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
of course, you have to include the doc/frame/view files
#include "SampleDoc.h" #include "SampleView.h" #include "MainFrm.h"
CSampleDocument): CSampleDocument inherits from CDFVDocument.
CMainFrame): CMainFrame inherits from CDFVFrameWnd of course, you have to include the according files.
CEditView (Return, Tab, ...). May be it is a bug inside CEditView regarding this application.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 Sep 2001 Editor: Nishant Sivakumar |
Copyright 2001 by Jean-Louis Guenego Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |