Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple SDII apps - How do I brigh them together into one app 1

Status
Not open for further replies.

mwr412

Programmer
Jan 9, 2002
23
0
0
US
I have programmed several SDI apps each with a document/view and CRecordset class. These apps all interface to an Access database using ODBC. My question, how can I integrate all thses funcitons into one app which can call the specific doc/view/recordset from a menu option for each.

I have tried moving the 3 classes from 2 of the apss into a new SDI framework but can't figure out how to switch between the doc/view/recordset which app wizard created to one of the 2 doc/view/recordsets I moved into the app.

Specifically I used the 3 classes CDocument, CRecordView, and CRecordset.

My finished app(s) will need to manipulate a large number of doc/view/recordsets and different tables within differnt databaes. Can anyone recomend a book that deals with this level of doc/view/recordset programming?

 
I think I've got to apologize. Some things I've previously said have probably misled you.

I've done SDI applications where I've been able to use the same DOC & VIEW classes for the life of the project but I dynamically built menus and toolbars based on what the current screen needed.

It is now very apparent to me that you need to use MDI for your project, as your requirements are very different from the ones I was working with. I would still exersize very tight control on your windows:

1) create tabs that change when the selected window changes
2) only allow the windows to be viewed as maximized, so they don't float around over and under each other.

Let me quote a couple of paragraphs from the book, "Programming Microsoft Visual C++, Fifth Edition", by David J. Kruglinski, George Shepherd and Scot Wingo [Microsoft Press](p.453):

[ul]Multiple Document Templates

An MDI application can support multiple document templates through multiple calls to the AddDocTemplate function. Each template can specify a different combination of document, view, and MDI child frame classes. When the user chooses New from the File menu of an application with multiple templates, the application framework displays a list box that allows the user to select a template by name as specified in the string resource (document type substring). Multiple AddDocTemplate calls are not supported in SDI applications because the document, view, and frame objects are constructed once for the life of the application.

NOTE: When your application is running, the application object keeps a list of active document template objects. The CWinApp member functions GetFirstDocTemplatePosition and GetNextDocTemplate allow you to iterate through the list of templates. These functions, together with the CDocTemplate member functions GetFirstDocPosition and GetNextDoc, allow you to access all of the application's document objects.

If you don't want the template list box, you can edit the File menu to add a New menu item for each document type.[/ul]

Let me know if you've got questions or want further explanation about what any of this means.

|-I I'm sorry that I didn't fully understand your situation and steered you wrong.
 
I meant to especially draw your attention to this paragraph:

[ul]Multiple AddDocTemplate calls are not supported in SDI applications because the document, view, and frame objects are constructed once for the life of the application.[/ul]
 
I was beginning to suspect that MDI was the solution as welll, but, in this case 'what you don't know' will hurt you!!! I started from scratch with a new framework based on MDI. I added a second View, Document, and Recordset class. Everything looks good and is basically working as I expect with the exception of today's queston:

When I start my app before the mainframe displays I get a small dialog box titled 'New' with 2 options in a listbox:

System
System

I have already figured out that each is refering to the 2 MDI templetes I have added to the project. When I select one or the other the appropriate view is being displayed by the app.

What I did was the following in the Initinstance:

// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.

CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_SYSTEMTYPE,
RUNTIME_CLASS(CSystemManagerDoc),
RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CSystemManagerView));
AddDocTemplate(pDocTemplate);
//
// My second Document/View templete
//
CMultiDocTemplate* pDocTemplateView1;
pDocTemplateView1 = new CMultiDocTemplate(
IDR_SYSTEMTYPE,
RUNTIME_CLASS(CView1Doc),
RUNTIME_CLASS(CChildFrame), RUNTIME_CLASS(CView1));
AddDocTemplate(pDocTemplateView1);

Accoreding to the MFC documentation on MDI I have all document/view must be registered via the MDI templete before calling the processshellcommands. So I did! That's when the app started poping up the dialog box I mention above. Obviously I don't want this dialog poping up. I want to select which view starts the app and then change when the user selects a funciton which needs to have it's on View/Document/Recorset etc.
 
I think this (or a variation) may help you (from same book as above, p.452). Just decide what document type you're going to start out with and call OpenNewDocument() passing the type as the parameter:

[ignore]
If you don't want the template list box, you can edit the File menu to add a New menu item for each document type. Code the command message handlers as shown below, using the document type substring from each template.

void CMyApp::OnFileNewStudent()
{
OpenNewDocument("Studnt");
}
void CMyApp::OnFileNewTeacher()
{
OpenNewDocument("Teachr");
}
Then add the OpenNewDocument helper function as follows:


BOOL CMyApp::OpenNewDocument(const CString& strTarget)
{
CString strDocName;
CDocTemplate* pSelectedTemplate;
POSITION pos = GetFirstDocTemplatePosition();
while (pos != NULL) {
pSelectedTemplate = (CDocTemplate*) GetNextDocTemplate(pos);
ASSERT(pSelectedTemplate != NULL);
ASSERT(pSelectedTemplate->IsKindOf(
RUNTIME_CLASS(CDocTemplate)));
pSelectedTemplate->GetDocString(strDocName,
CDocTemplate::docName);
if (strDocName == strTarget) { // from template's
// string resource
pSelectedTemplate->OpenDocumentFile(NULL);
return TRUE;
}
}
return FALSE;
}
[/ignore]
 
Oh, yeah. You can also add the following line somewhere shortly after you register the Document types:

// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

// no empty document window on startup
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) {
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
}
 
Thanks,

This was exactly were I was headed. I had figured out part of this but you just filled in the blanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top