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
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);