Click here to Skip to main content
13,002,343 members (77,496 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I want to create a SDI application with dynamic views.

I found that normally the view is created inside the function InitInstance() of application class using the code below.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
	RUNTIME_CLASS(CMyMainFrame),       // main SDI frame window
if (!pDocTemplate)
	return FALSE;
if (!ProcessShellCommand(cmdInfo))
	return FALSE;

I want to create the view based on the user input...for eg, on selecting an item in combobox.

How should i create a view outside the InitInstance() function???

Please help..
Posted 3-Apr-13 0:38am
Richard MacCutchan 3-Apr-13 7:06am
You can move this code elsewhere so it becomes dynamic. If memory serves there is a sample somewhere on MSDN that shows how to do it.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The view is not created here in InitInstance(). The view will be created by the CMyAppDoc class when a new (empty) document is created or an exiting one is opened. In your code this is initiated by calling ProcessShellCommands().

If you need different kinds of views, you can add multiple templates in InitInstance() which must be of type CMultiDocTemplate and use one of them to create the frame window (which is the parent window of the view) from within your CMyAppDoc class.

While your application is then still SDI, this requires some work in your CMyAppDoc class. To create a frame (e.g. from within OnNewDocument() and OnOpenDocument() of your document class), call the CreateNewFrame() and InitialUpdateFrame() member functions of the selected CMultiDocTemplate passing the pointer to your document class.
Vineeth.B 3-Apr-13 8:09am
Thanks for the solution.
Let me tell you onething. there will be only one view will be active at a time. So i don't think that CMultiDocTemplate need to be used. My application is SDI. Also, the main window should be created without a view initially. When the user select one from the combobox, an apprpriate view must be created. That's my requirement.
Jochen Arndt 3-Apr-13 8:26am
CMultiDocTemplate must be used when using different templates for different views even when only one view is used at time. SDI means single document. It is still SDI when using different types of views or even multiple views for one document (e.g. multiple tables from one database document).

To avoid creation of an empty document at startup, just remove the call to ProcessShellCommands() or call it only when a file has been passed on the command line (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen).

Instead show a dialog box to select the type of view. Select the template according to the type and store the pointer in a member variable that can be accessed from your document class. Then call CWinApp::OpenDocumentFile(). This will call OnOpenDocument() (or OnNewDocument() when the file name is NULL) of your document class. There get the pointer to the template and create the frame which contains the view.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 3 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100