Solved

Overriding Document selector when more than one Document exists

Posted on 2004-10-13
4
166 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now