Solved

Overriding Document selector when more than one Document exists

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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