CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1

    How to Call OnNewDocument from the code

    Does anyone know how to call the OnNewDocument from the code. What I want to do is basically if the user clicks the left mouse button in a specific region of the window, then a new document should be opened. However I do not want this document to be maximized but it should just pop up as a dialog on the existing window. Please help !!

  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    Unless I missed something:
    Document is not a window and usually in used in doc/view architecture supporting application.
    Therefore you cannot "popup document as dialog".
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    what i mean is I want to open a new document but dont want it to maxmize. Hence the underlying document can still be seen. Am I clear now? Please help me.

  4. #4
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    I thing I maybe understand now.

    You are trying to use File New (for example) to create new file and you do not want new child frame to overlap existing one.

    Does that describe what you are trying to accomplish?

    By the way a reason I am confused is (as I have mentioned before) the way you are referring to a document.
    When you create new file in MFC application supporting doc/view architecture, framework creates new document that governs view contained in child a frame.
    Child frame is the window that you resize and move around, view complies with changes and document tell a view what and possibly how to display data.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Yes thats the thing I want to do. Basically call File-New from somewhere in my code.

  6. #6
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: How to Call OnNewDocument from the code

    Originally posted by adwaitjoshi
    What I want to do is basically if the user clicks the left mouse button in a specific region of the window
    I still do not have enough information to give you very specific answer that only applies to your case.

    For example I do not know what window you want to have your click handled, nor do I know what kind od application you are using (MDI, SDI)?

    I will just assume you are doing MDI and handle click in a view window.
    Code:
    void CSomeView::OnLButtonUp(UINT nFlags, CPoint point)
    {
      CBaseView::OnLButtonUp(nFlags, point);
      
      // Do your stuff here and:
    
      AfxGetMainWnd()->SendMessage(WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, CN_COMMAND), NULL);
    }
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  7. #7
    Thanks that worked great !!!!!

  8. #8
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    You are welcome.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  9. #9
    Join Date
    Jan 2001
    Posts
    306
    or you can do it like this:

    ((CYourApp * )AfxGetApp())->m_pDelcareThisDocTemplate->OpenDocumentFile();

  10. #10
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    You can do:
    Code:
    (dynamic_cast<CWhateverApp*>(AfxGetApp()))->OnFileNew();
    Except you need to have an override of of OnFileNew (a handler for the ID_FILE_NEW command) since OnFileNew is protected in CWinApp. When a handler for the ID_FILE_NEW command is added by the ClassWizard it is made public.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  11. #11
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    Of course we can do it using many different approaches. In my opinion, the simplest and using framework as much as possible is the best.
    I do not understand why raise difficulty level when one line of code (without any additional code instantiating and maintaining document template) works.

    This command message uses default MFC message routing mechanism. Application object after receiving this command will call base class implementation automatically, since Class wizard maps that call in the app:
    Code:
    	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured