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

[Webinar] Streamline your web hosting managementRegister Today

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

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();
      pView = pDoc->GetNextView(pos);
      {                                      pView->GetParentFrame()->ActivateFrame();
      return TRUE;

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


This will display a new view with a menu IDR_Test
Change  pDocTemplateForScrolling
to  pDocTemplateForTest  eveywhere in the above given code snippet
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
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.
All Courses

From novice to tech pro — start learning today.