Document Templates
Jonas =?iso-8859-1?Q?Andur=E9n?= -- jonas.anduren@mailbox.swipnet.se Sunday, October 13, 1996 Environment : VC4.2 and Win95 Can I have multiple documenttemplates without getting the documenttype selection dialogbox? Background: I have an application with a static splitterwindow. There is a different CFormview class in each pane. I want both of these panes to access the same document object so I created two documenttemplates that points to the same documentclass. But here is my problem. When I have two document templates I allways get the dialogbox where I am to select documenttype. I have stepped through the code and I can't see that I can get around this without messing with the MFC source code (I don't want that). Am on the right track or should I consider an alternative? Thanks in advance for any tip... J.A
Randy Sales -- rsc@halcyon.com Monday, October 14, 1996 [Mini-digest: 5 responses] Jonas =?iso-8859-1?Q?Andur=E9n?= wrote: > > Environment : VC4.2 and Win95 > > Can I have multiple documenttemplates without getting the documenttype > selection dialogbox? Yes, you can. I had a similar problem in that I wanted to emulate how Developer Studio brings up the file type selection dialog _only_ when File::New is selected, not when Ctrl+N or the New File button is pressed. The way I solved this was to create a different message ID for the Ctrl+N accelerator (and the New File Button), something like ID_FILE_NEW_TESTFILE. I then just used Class Wizard to add a new COMMAND handler for this message ID in my CWinApp derived class. The command handler looks like this: void CIdeApp::OnFileNewTestfile() { POSITION Pos = GetFirstDocTemplatePosition(); GetNextDocTemplate(Pos)->OpenDocumentFile(NULL); } There's nothing special here, it just emulates what the MFC code does in CDocManager::OnFileNew() when you have more than one document template. But instead of presenting the file type selection dialog, I just force the creation of an empty document using the first document template in the DocTemplate list. (This will be the first one you created in InitInstance by a call to AddDocTemplate.) Hope this helps. Randy Sales -- RS Consulting 1521 1/2 Cedar Street Everett, WA 98201 Phone 206-259-1056 Fax 206-259-1315 email rsc@halcyon.com > > Background: > I have an application with a static splitterwindow. There is a different > CFormview class in each pane. I want both of these panes to access the > same document object so I created two documenttemplates that points to > the same documentclass. But here is my problem. When I have two document > templates I allways get the dialogbox where I am to select documenttype. > I have stepped through the code and I can't see that I can get around > this without messing with the MFC source code (I don't want that). Am on > the right track or should I consider an alternative? > > Thanks in advance for any tip... > > J.A -----From: ganeshs@nationwide.com What you need is just a _single_ (SDI) document template object, which has the CRuntimeClass * for any one of the views. Create the views in the Splitter (after you create the splitter window) using CSplitterWnd::CreateView(), in the OnCreateClient() override in your CFrameWnd-derived class... / ___| / ___| __ _ _ __ ___ ___| | I do not speak for \___ \ | | _ / _` | '_ \ / _ \/ __| '_ \ Tata Unisys or ___) | | |_| | (_| | | | | __/\__ \ | | |Nationwide Ins. |____(_) \____|\__,_|_| |_|\___||___/_| |_|------------------ -----From: Hugh RobinsonMake the second part of the string resource which is associated with the second view blank, i.e. instead of \nDoc\nDoc description\n..... make it \nDoc\n\n... This will stop the dialog box from appearing -----From: "Manos D. Anastasiadis" There are a couple of solutions out of the top of my head: 1) *Don't* AddDocTemplate() your template after you create it (you can still use it to create docs/views/frames on your own) 2) Write a handler for ID_FILE_NEW / ID_FILE_OPEN to popup different dialog boxes (without the additional file types) /*==================================* * Manos D. Anastasiadis * * Computer Engineer * * Technical University of Crete * * Mu.S.I.C. * * manos@ced.tuc.gr * *==================================*/ -----From: "Michael J. Morel" The answer lies in your Document string resources. Choose one view to = be the one created by default when a new doc is created. For this view, = the document string looks something like this (this is from a sample = program of mine, so don't mind the names): =09 IDR_FORUMTYPE: "\nForum\nForum\n\n\nForum.Document\nForum Document" Then, for your other views, the doc string looks like: IDR_THREADTYPE "ThreadView\nForum\n" These strings are defined in the resource editor. See the documentation = for the GetDocString function for an explanation of the various parts of = this string. Mike Morel Mushroom Software Home of MFC For Yourself http://www.mushroomsoft.com/mushroom
Shrikanth Swaminathan -- sshri@csi-gmbh.de Monday, October 14, 1996 [Mini-digest: 5 responses] have a look at the Checkbook sample. It does what u want. > From: Jonas Andurйn> To: mfc-l@netcom.com > Subject: Document Templates > Date: Sunday, October 13, 1996 2:04 PM > > Environment : VC4.2 and Win95 > > Can I have multiple documenttemplates without getting the documenttype > selection dialogbox? > [snip] > J.A -----From: kmg@gregcons.com (Kate Gregory) You need to edit the string table. The prompt to be used in the File New "what kind of file?" routine is in the "caption" for your IDR_SOMETHINGTYPE resource. That is a number of small strings separated by \n, and they are (cutting and pasting from a book file here, excuse the formatting) : *** begin bulleted list [1b] Window Title: used by SDI apps in the title bar. [1b] Document Name: used as the root for default document names. [1b] File New Name: prompt in the File New dialog for file type. [1b] Filter Name: an entry for the drop down box List File of Type in the File Open dialog. [1b] Filter Extension: the extension that matches the filter name. [1b] Registry File Type ID: a short string to be stored in the registry. [1b] Registry File Type Name: a longer string to be shown in dialog boxes involving the registry. *** end bulleted list Leave the "File New Name" blank, that is nothing between the \n and the next \n, to take away the name. The dialog only comes up when there are multiple names to choose among (or multiple views each associated with the same name), so taking the names away from each resource prevents the dialog. Kate -- Kate Gregory, kate@gregcons.com www.gregcons.com Watch for my completely new edition of Using Visual C++ this fall... Using Visual C++ 4.2 will be in stores by late October. -----From: "Alexander Grigoriev" Yes, just don't call AddDocTemplate for the additional templates. -----From: Joseph Jones I beleive you need to override the OnNewDocument function to get rid of the multiple template selection dialog box. Look at the code for single dialog template creation and use that. joe -----From: "PJ Durai" Hi J.A. I had a similar requirement. Here is what you need to do to make it work. Do NOT create a second doc template. Leave the InitInstance as it was. ( I am presuming it is a SDI, generated by AppWizard) You will have to do something along these lines in your CMainFrame::OnCreateClient. (I had 4 views. ) BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { m_wndSplitter.CreateStatic (this, 2, 2); CRect rect; GetClientRect (rect); CSize size; ... m_wndSplitter.CreateView ( 0,0, RUNTIME_CLASS (CTestView), size, pContext); // this view is the default one generated // by appwizard and in DocTemplate. ... calculate size etc.. m_wndSplitter.CreateView ( 0,1, RUNTIME_CLASS (CImageView), size , pContext); m_wndSplitter.CreateView ( 1,0, RUNTIME_CLASS (CTagView), size , pContext); m_wndSplitter.CreateView ( 1,1, RUNTIME_CLASS (CLogView), size , pContext); ... return TRUE; // dont call the superclass function. } Hope this helps. pj
| Вернуться в корень Архива |