Solved

A Weird MFC application!

Posted on 2003-12-09
9
284 Views
Last Modified: 2013-11-20
I have a SDI MFC applicaiton, it runs fine until I add a class (a form class, not a MFC class), when it runs, a small dialog appear with 2 option (in a list box, I suppose)to choose , but it's not the thing I want, how can I get rid of this dialog when the program starts! Thankx
0
Comment
Question by:tinh911
9 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 9902786
Can you tell us what the dialog is telling? Do you know at what place in your code this dialog appears?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9902871
Do you have two different views to one document?  It could be asking which you want to use.  If that is the case have a look at the ChkBook MFC sample
0
 

Author Comment

by:tinh911
ID: 9902904
Yes, I have more than 2 views!
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:tinh911
ID: 9902927
In the method
OnCreateClient(...){
      m_Splitter.CreateStatic(this, 1, 2);
      m_Splitter.CreateView(0,0,RUNTIME_CLASS(FormView),...);//the one I mention!
      m_Splitter.CreateView(0,1,RUNTIME_CLASS(TreeView)).....
}

After I replace the line:
    m_Splitter.CreateView(0,0,RUNTIME_CLASS(FormView),...);
with this
    m_Splitter.CreateView(0,0,RUNTIME_CLASS(AnotherView),...);
AnotherView is MFC class derived from CListView!
That dialog still appears when my program starts!
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 9902969
I assume this dialog is asking which view you want.
The CHKBOOK sample has two views to one document.  There it tells you how to stop this dialog appearing.  
0
 

Author Comment

by:tinh911
ID: 9902985
Thankx!
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9903023
MSDN Says

if the program has multiple document templates, CWinApp::OnFileNew will prompt the user with a dialog box asking which type of document to open. The programmer may already know which type of CMultiDocTemplate to use, and therefore may not want to prompt the user because it would be inappropriate in the given context of the application.



MORE INFORMATION
Assuming the application was originally created with AppWizard, the undocumented CMultiDocTemplate::OpenDocumentFile function can be used to create a new CMultiDocTemplate based window. There are several steps involved:



Add a CMultiDocTemplate pointer to your CWinApp derived class:

      class CMyApp : public CWinApp
      {
        ...

       public:
        CMultiDocTemplate* m_pDocTemplate;

        ...

      }
NOTE: If you plan to use multiple document types, you must create a CMultiDocTemplate pointer member variable for each document type.


In the call to CWinApp::InitInstance, remove the creation of the CMultiDocTemplate from the call to AddDocTemplate. Set the pointer to point to the new CMultiDocTemplate. Use the pointer to call AddDocTemplate:

      BOOL CMyApp::InitInstance()
      {
        ...

        m_pDocTemplate = new CMultiDocTemplate(IDR_TEXTTYPE,
                                      RUNTIME_CLASS(CMyDoc),
                                      RUNTIME_CLASS(CMDIChildWnd),
                                      RUNTIME_CLASS(CMyView));

        AddDocTemplate(m_pDocTemplate);

        ...

      }



Use the pointer to call CMultiDocTemplate::OpenDocumentFile with a NULL parameter to create the new window. For this example, assume there is a button in a CView window. In the BN_CLICKED handler for the button, we want to create a window based on m_pDocTemplate:

      void CMyView::OnNewWindowButtonClicked()
      {
          CMyApp* pApp = (CMyApp*)AfxGetApp();
          pApp->m_pDocTemplate->OpenDocumentFile(NULL);
      }
This same technique could be used to create a CSingleDocTemplate based window in a Single Document Interface (SDI) application. However, it is not necessary. Because there is only one document template for the application, calling OnFileNew() will create the new window without prompting the user for the type of document.

Rosh :)
0
 
LVL 1

Expert Comment

by:luvjd
ID: 9903194
Hi tinh911
...As u said it is showing two view classes ( with a "new" dialog box) ..
comment the following line of the view which u do not want to display...


AddDocTemplate(pDocTemplate);

If there are more Document templates added , system ask the user to select which template to use.. this is what happened in your case..

:)
Luv..
Jd..
0
 

Author Comment

by:tinh911
ID: 9910404
I want to thank all of you for your help!
Thank again! :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 52
bobThere java chalenge 45 94
xyBalance chalenge 58 96
changeXy challenge 13 88
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question