how to use "OnNewDocument" from cview or cmainframe class
-
Hi everyone, I am using an activex control which i have inserted onto a formview of an mdi application.when i press File->new option i get a new window with the activex in it. Now i want to implement the same funtionality on a button press. i want the same results as that of File->New.How do i achieve it from the CFormView or the Cmainframe class.
-
Hi everyone, I am using an activex control which i have inserted onto a formview of an mdi application.when i press File->new option i get a new window with the activex in it. Now i want to implement the same funtionality on a button press. i want the same results as that of File->New.How do i achieve it from the CFormView or the Cmainframe class.
Maybe something like this:
if (AfxGetApp()->m_pDocManager)
AfxGetApp()->m_pDocManager->OnFileNew();Mark
Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."
-
Maybe something like this:
if (AfxGetApp()->m_pDocManager)
AfxGetApp()->m_pDocManager->OnFileNew();Mark
Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."
O' My God that really worked like magic.. But how do i get a pointer to each view. I want to pass data to the view
-
O' My God that really worked like magic.. But how do i get a pointer to each view. I want to pass data to the view
:) I'm glad it worked. That's how MFC does it but it's using an undocumented variable (although it's worked for as long as I can remember). You probably could just give your button the id ID_FILE_NEW and it would have worked like magic too :) I thought for sure someone here would jump on me for that one LOL.
chaitannya_m wrote:
But how do i get a pointer to each view. I want to pass data to the view
Which view? The one just created? The view just created should be the active view. To get the active view in MDI;
// this is the MFC example from the docs
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;// Get the active MDI child window.
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();// or CMDIChildWnd *pChild = pFrame->MDIGetActive();
// Get the active view attached to the active MDI child
// window.
CMyView *pView = (CMyView *) pChild->GetActiveView();To iterate through all views, one way is to iterate through all documents and their associated views:
// Iterate through doc templates
POSITION DocTemplatePos = AfxGetApp()->GetFirstDocTemplatePosition();
while (DocTemplatePos != NULL)
{
CDocTemplate *pTmpl = AfxGetApp()->GetNextDocTemplate(DocTemplatePos);// Iterate through documents for the current template
POSITION DocPos = pTmpl->GetFirstDocPosition();
while (DocPos != NULL)
{
CDocument *pDoc = pTmpl->GetNextDoc(DocPos);**// Iterate through views for the current document** // You could use CDocument::UpdateAllViews() or ... POSITION ViewPos = pDoc->GetFirstViewPosition(); while (ViewPos != NULL) { CView \*pView = pDoc->GetNextView(ViewPos); **// Do something with the current view** }
}
}Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."