Solved

Overriding Document selector when more than one Document exists

Posted on 2004-10-13
4
170 Views
Last Modified: 2013-11-20
Hi

I have a MDI app that has two document types. When it starts I want to open an instance
of the first document automatically but cannot workout how to do this before the framework
displays the select document dialog.

Can anyone help
Thanks
ja
0
Comment
Question by:ja_rasta
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 125 total points
ID: 12304175
//Handle command ID_FILE_NEW
BEGIN_MESSAGE_MAP(CdcmviewerApp, CWinApp)

      ON_COMMAND(ID_FILE_NEW, OnFileNew)

END_MESSAGE_MAP()

void CdcmviewerApp::OnFileNew()
{
      m_pSearchDocTemplate->OpenDocumentFile(NULL); //CMultiDocTemplate* m_pSearchDocTemplate;
      CMainFrame *pMainFrame = (CMainFrame*)AfxGetMainWnd();
      CMDIChildWnd* pMDIActive = pMainFrame->MDIGetActive();
      SearchView *pview = (SearchView*)pMDIActive->GetActiveView();
      pMDIActive->GetActiveDocument()->SetTitle(_T("Readme"));
      pMDIActive->SetTitle(_T("Readme"));
      pMainFrame->MDIMaximize(pMDIActive);
      pMainFrame->MDIActivate(pMDIActive);//activate the view so that WM_KEYDOWN can work

}

welcome to www.fruitfruit.com
0
 

Author Comment

by:ja_rasta
ID: 12308366
Thanks for the reply.

I know how to open a particular document from code the problem
is when you have two document types and the app is starting up. The OnFileNew
command is not used by the framework at this point when it prompts
you to select the document you want to open. I want to stop this dialog
from being displayed and do it automatically. Your code will do this, but only if
the user selects File>New.

Thanks
ja
0
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12314101
override another method

CDocument* CdcmviewerApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
      CDocument* pDoc = NULL;
      bool is_text_file = false;
      if(end_with(lpszFileName,_T(".txt"),true)|| end_with(lpszFileName,_T(".ini"),true)
            ||end_with(lpszFileName,_T(".h"),true)||end_with(lpszFileName,_T(".cpp"),true)
            ||end_with(lpszFileName,_T(".xml"),true)||end_with(lpszFileName,_T(".hpp"),true)
            ||end_with(lpszFileName,_T(".c"),true)||end_with(lpszFileName,_T(".cxx"),true)
            ||end_with(lpszFileName,_T(".html"),true) )
      {
            pDoc = m_pEditDocTemplate->OpenDocumentFile(lpszFileName);
            is_text_file = true;
      }
      else
        pDoc = m_pImageDocTemplate->OpenDocumentFile(lpszFileName);
      CMainFrame *pMainFrame = (CMainFrame*)AfxGetMainWnd();
      CMDIChildWnd* pMDIActive = pMainFrame->MDIGetActive();
      if(is_text_file)
      {
            CEditView *pview = (CEditView*)pMDIActive->GetActiveView();
            pMDIActive->SetTitle(lpszFileName);
            CEdit& wndEdit = pview->GetEditCtrl();
            pview->SetTabStops(4);
            wndEdit.ModifyStyle(ES_WANTRETURN,ES_AUTOVSCROLL|ES_MULTILINE|ES_AUTOHSCROLL);
            CFile ftmp;
            if(ftmp.Open(lpszFileName,CFile::modeRead) && ftmp.GetLength()>0)
            {
                  std::auto_ptr<char> buf(new char[ftmp.GetLength()+1]);
                  if(buf.get())
                  {
                        ftmp.Read(buf.get(),ftmp.GetLength());
                        buf.get()[ftmp.GetLength()] = 0;
                        wndEdit.SetWindowText(buf.get());
                  }
                  else
                  {
                        wndEdit.SetWindowText(_T("failed to read file"));
                  }
            }
            wndEdit.Invalidate();

      }
      pMainFrame->MDIMaximize(pMDIActive);
      pMainFrame->MDIActivate(pMDIActive);//activate the view so that WM_KEYDOWN can work
      return pDoc;      
}

welcome to www.fruitfruit.com
0
 

Author Comment

by:ja_rasta
ID: 12317981
Hi

Have you actually tried the code you are providing to solve the question I have asked?
This code does not solve the problem

ja
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
repeatSeparator  java  challenge 13 58
Add content to output file 4 67
method notes when mouse over in eclipse 5 87
canBalance challenge 34 98
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

820 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