Solved

Overriding Document selector when more than one Document exists

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 76
Named range not carried over 10 62
matchUp  challenge 6 53
tripleUp challenge 7 74
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. …
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…
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

21 Experts available now in Live!

Get 1:1 Help Now