In my application(MDI AppWizard exe) I want to create a new child
window
when i click a certain menu item in my main menu (like in File->New)
where I can display a graph. Please tell me how I can a create a new
child window and use it.

Thanx in advance,
Rishabh

Re: Creating MDI Child Windows by Guido

Guido
Tue Jul 24 06:32:14 CDT 2007

Save your CDocTemplate* in your WinApp class. Then you can use
OpenDocumentFile:
m_pDocTemplateTheChildWnd->OpenDocumentFile(NULL);

Regards,
Guido



Re: Creating MDI Child Windows by rishabh

rishabh
Tue Jul 24 07:38:27 CDT 2007

On Jul 24, 4:32 pm, "Guido Franzke" <guido...@yahoo.de> wrote:
> Save your CDocTemplate* in your WinApp class. Then you can use
> OpenDocumentFile:
> m_pDocTemplateTheChildWnd->OpenDocumentFile(NULL);
>
> Regards,
> Guido

Thank u for the reply. But I could not get you clearly as I am new to
Visual C and MFC. Could u please reply back with a detailed solution.
It will be of great help.


Re: Creating MDI Child Windows by Guido

Guido
Tue Jul 24 07:51:59 CDT 2007

Ok.
In your header file of the CWinApp derived class insert a new member:

MyWinApp.h:

class CMyWinApp : public CWinApp
{
// ....
public:
CMultiDocTemplate* m_pDocTemplateMyChildWnd;

};


in the source file
MyWinApp.cpp:

in the constructor:
CMyWinApp::CMyWinApp()
{
// ...
m_pDocTemplateMyChildWnd = NULL; // always initialize pointers!!

}

in OnInitInstance of your CMyWinApp class you must change the local pointer
to the member pointer:

before:
BOOL CMyWinApp::InitInstance()
{
// ...
CMultiDocTemplate* pDocT = new CMultiDocTemplate(IDR_CHILDWND_TYPE,
RUNTIME_CLASS(CMyChildDoc),
RUNTIME_CLASS(CMyChildFrame),
RUNTIME_CLASS(CMyChildView));
if (!pDocT) return FALSE;
AddDocTemplate(pDocT);
// ...
}

change to:
BOOL CMyWinApp::InitInstance()
{
// ...
m_pDocTemplateMyChildWnd = new CMultiDocTemplate(IDR_CHILDWND_TYPE,
RUNTIME_CLASS(CMyChildDoc),
RUNTIME_CLASS(CMyChildFrame),
RUNTIME_CLASS(CMyChildView));
if (!m_pDocTemplateMyChildWnd) return FALSE;
AddDocTemplate(m_pDocTemplateMyChildWnd);
// ...
}

Now you have the document template pointer which you can use to open a new
child window, e.g. the following way:

void CMyWinApp::OpenNewWindow()
{
m_pDocTemplateMyChildWnd ->OpenDocumentFile(NULL);
}

You could call this routine from a menu item in CMainFrame or using a
toolbar button for example. Whenever you call OpenNewWindow, a new mdi
window will be opened.

HTH Guido



Re: Creating MDI Child Windows by Guido

Guido
Tue Jul 24 08:00:21 CDT 2007

After having called OpenDocumentFile, the document's class function
OnNewDocument is called. Here I read the document's data that is displayed
in the view afterwards.


BOOL CMyChildDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
{
return FALSE;
}

if (!ReadTheContentsOfTheNewWindow())
{
return FALSE;
}

// ok
SetTitle("This is the new window");

return TRUE;
}


Regards,
Guido



Re: Creating MDI Child Windows by rishabh

rishabh
Tue Jul 24 08:26:36 CDT 2007

On Jul 24, 6:00 pm, "Guido Franzke" <guido...@yahoo.de> wrote:
> After having called OpenDocumentFile, the document's class function
> OnNewDocument is called. Here I read the document's data that is displayed
> in the view afterwards.
>
> BOOL CMyChildDoc::OnNewDocument()
> {
> if (!CDocument::OnNewDocument())
> {
> return FALSE;
> }
>
> if (!ReadTheContentsOfTheNewWindow())
> {
> return FALSE;
> }
>
> // ok
> SetTitle("This is the new window");
>
> return TRUE;
>
> }
>
> Regards,
> Guido

Thank u so much


Re: Creating MDI Child Windows by rishabh

rishabh
Tue Jul 24 08:35:19 CDT 2007

On Jul 24, 6:26 pm, rishabh.saxena.i...@gmail.com wrote:
> On Jul 24, 6:00 pm, "Guido Franzke" <guido...@yahoo.de> wrote:
>
>
>
> > After having called OpenDocumentFile, the document's class function
> > OnNewDocument is called. Here I read the document's data that is displayed
> > in the view afterwards.
>
> > BOOL CMyChildDoc::OnNewDocument()
> > {
> > if (!CDocument::OnNewDocument())
> > {
> > return FALSE;
> > }
>
> > if (!ReadTheContentsOfTheNewWindow())
> > {
> > return FALSE;
> > }
>
> > // ok
> > SetTitle("This is the new window");
>
> > return TRUE;
>
> > }
>
> > Regards,
> > Guido
>
> Thank u so much

Can I ask for some more help? I have used ur way and its working fine.
But i still have a little problem. I will explain to you my situation
and please let me knoe if you can help.
I have an MDI App. I have a doc and view opened displaying some data.
Now in my menu I have a View->Plot item (ID_VIEW_PLOT) clicking on
which a new window (popup) will open on which I can display a graph.
To display a graph i need a CFormView derived view window which gets
displayed on clicking View->Plot. Can u detail me out how i can do
this. I need to have the handler for ID_VIEW_PLOT in CFormView derived
class and not in CWinApp class. With your previous solution I am able
to create new windows. But now i want 2 type of view classes wherein
the form view opens only if i click the menu item.
Thanx in advance.


Re: Creating MDI Child Windows by Guido

Guido
Tue Jul 24 09:29:09 CDT 2007


In which class do you handle ID_VIEW_PLOT? Don't use CMyWinApp but
CMainFrame. Then you can switch to the actual child window the following
way:

Mainfrm.cpp:

ON_COMMAND(ID_VIEW_PLOT, OnMenuViewPlot)

void CMainFrame::OnMenuViewPlot()
{
CMyChildView* pView = NULL;
CMyChildDoc* pDoc = NULL;

CChildFrame* pChild = (CChildFrame*)MDIGetActive();
if (pChild) pView = (CMyChildView*)pChild->GetActiveView();
if (pView) pDoc = pView->GetDocument();

if (!pDoc) return; // not found?!

// With these pointers you can handle your drawing. For example:

pView->SendMessage(WM_PAINT);

}

Regards, Guido



> Can I ask for some more help? I have used ur way and its working fine.
> But i still have a little problem. I will explain to you my situation
> and please let me knoe if you can help.
> I have an MDI App. I have a doc and view opened displaying some data.
> Now in my menu I have a View->Plot item (ID_VIEW_PLOT) clicking on
> which a new window (popup) will open on which I can display a graph.
> To display a graph i need a CFormView derived view window which gets
> displayed on clicking View->Plot. Can u detail me out how i can do
> this. I need to have the handler for ID_VIEW_PLOT in CFormView derived
> class and not in CWinApp class. With your previous solution I am able
> to create new windows. But now i want 2 type of view classes wherein
> the form view opens only if i click the menu item.
> Thanx in advance.
>



Re: Creating MDI Child Windows by rishabh

rishabh
Wed Jul 25 03:08:58 CDT 2007

Thanx again Guido,
As you had asked, I want the handler of ID_VIEW_PLOT to be in
CMyView , a class that has been derived from CFormView and is
different from the View class that has been created by appwizard. I
will add the handler in CMainframe class n try that out. If you have
more exact solution to the problem, which must be clear by now, then
plz write it back. Note that in my code for handler i need to display
this new child window (come out as a popup) and then display a graph
(like u have in Matlab, if u have used it). Please reply back.


Re: Creating MDI Child Windows by Guido

Guido
Wed Jul 25 05:44:47 CDT 2007

So you want to use a second view in your window. I once saw such a question
in this newsgroup. I've been searching here but have not found the replies.
I'm sorry I've never programmed that, so ask the newsgroup again.
Regards.


<rishabh.saxena.iitd@gmail.com> schrieb im Newsbeitrag
news:1185350938.230576.36280@22g2000hsm.googlegroups.com...
> Thanx again Guido,
> As you had asked, I want the handler of ID_VIEW_PLOT to be in
> CMyView , a class that has been derived from CFormView and is
> different from the View class that has been created by appwizard. I
> will add the handler in CMainframe class n try that out. If you have
> more exact solution to the problem, which must be clear by now, then
> plz write it back. Note that in my code for handler i need to display
> this new child window (come out as a popup) and then display a graph
> (like u have in Matlab, if u have used it). Please reply back.
>



Re: Creating MDI Child Windows by Guido

Guido
Wed Jul 25 05:51:27 CDT 2007

I've found the question and replies in the newsgroup
microsoft.public.vc.mfc

"Clipping the MainFrame View with another View" on Mai, 9 at 19:35, asked by
AVee.

HTH