CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    7

    How do I open a CRecordView from a menu?

    I know how to open dialogs, etc., from a menu option, but I can't seem to even get started with a record view. From MainFrm.cpp (which is where I have placed the menu selector) I try the following:

    void CMainFrame::OnViewInventory()
    {
    CMyRecordView hInventoryView;

    }

    ERROR! I can't even declare an item of this class because the constructor is protected due to the need for dynamic creation.

    Not to be deterred, I dutifully looked up how to dynamically create objects and tried the following:

    void CMainFrame::OnViewInventory()
    {
    CRuntimeClass* pRuntimeClass = RUNTIME_CLASS( CMyRecordView );
    CObject* pObject = pRuntimeClass->CreateObject();
    ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CMyRecordView ) ) );
    }

    Great, no errors! But still nothing happens when I select the menu item for this process. So, how do I create this CRecordView?

    Thanks for any help!

    John

    ----

    "Try not. Do, or do not. There is no try." - Yoda

  2. #2
    Join Date
    Apr 1999
    Posts
    23

    Re: How do I open a CRecordView from a menu?

    It depends on whether you are using a SDI or MDI. What you need to do is to ask the DocTemplate to create a new document that will create a new view.
    The DocTemplate is created in the InitInstance of the App class.
    From the mainframe you can do the following to create a new document and view.

    pDocTemplate->OnOpenDocument(NULL);




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