?
Solved

Overriding Document selector when more than one Document exists

Posted on 2004-10-13
4
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 375 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

752 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