Menus

Can a Child Window of MDI have a menu item ? If yes, pls tell me how to do it with an example.Very Urgent.
gurukg102498Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mikeblasConnect With a Mentor Commented:
You can't. MDI Child Windows don't support menus.

If your requirement is an absolute must, your only alternative is to start rewriting the MDI framework supplied by Windows. You'll have to create your own top-level window, then manage phony MDI child frame windows yourself. YOu can give those menus.

But you'll need to work out all the notifications, management of the "Window" menu, and layout chorse by yourself.

..B ekiM
0
 
bhatCommented:
Yes ,U certainly can.

Let say  U want to popup a view say TestView.
Do following things
Add a Dialog with style "child " & Border "none"
Add a class CTestView derived from CFormView

Declare this in Application.h file
CMultiDocTemplate* pDocTemplateForScrolling;

In the initinstance of the application
pDocTemplateForTest = new CMultiDocTemplate(
IDR_TEST, // Menu
RUNTIME_CLASS(CTestDoc),            RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTestView));
AddDocTemplate(pDocTemplateForTest);
      
where CTestView is derived from CFormview

Let us say U have a menu item ViewTest in the app class
In the  ViewTest() function
void  CTestApp :: ViewTest()
{
CreateOrActivateView((CMDIFrameWnd*)m_pMainWnd,pDocTemplateForScrolling,(RUNTIME_CLASS(CTestView)));
}

BOOL CTestApp::CreateOrActivateView(CMDIFrameWnd* pMDIFrameWnd,CDocTemplate* pTemplate,CRuntimeClass* pViewClass)
{
CMDIChildWnd* pMDIActiveChild = (CMDIChildWnd*)pMDIFrameWnd->MDIGetActive();
CMDIChildWnd* pNewFrameWnd = NULL;
if(pMDIActiveChild != NULL)
{
CDocument* pDoc = pMDIActiveChild->GetActiveDocument();
CView *pView;
      POSITION pos;
      pos = pDoc->GetFirstViewPosition();
while(pos)
{
      pView = pDoc->GetNextView(pos);
      if(pView->IsKindOf(pViewClass))
      {                                      pView->GetParentFrame()->ActivateFrame();
                                     (pView->GetParent())->ShowWindow(SW_RESTORE);
      return TRUE;
      }

}
pNewFrameWnd = ((CMDIChildWnd*)pTemplate->CreateNewFrame(pDoc,NULL));      pTemplate->InitialUpdateFrame(pNewFrameWnd,pDoc);
            pDoc->SetTitle("");
}
else
{
pNewFrameWnd = ((CMDIChildWnd*) pTemplate->OpenDocumentFile(NULL));
}
if(pNewFrameWnd == NULL)
      return FALSE;
      return TRUE;

}


This will display a new view with a menu IDR_Test
0
 
bhatCommented:
Change  pDocTemplateForScrolling
to  pDocTemplateForTest  eveywhere in the above given code snippet
0
 
mikeblasCommented:
Uh, doesn't this put a different menu on the active MDI Parent Frame depending on which MDI Child frame is active?  I thought gurukg wanted to put menus on each child frame window--on the child window itself, not on the frame.

..B ekiM
0
 
gurukg102498Author Commented:
Mu main aim is to create a menu iten for the child window and not on the main window(frame).Can anybody tell me how to do it ? It is very urgent requirement.
0
All Courses

From novice to tech pro — start learning today.