Link to home
Start Free TrialLog in
Avatar of gurukg102498
gurukg102498

asked on

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.
Avatar of bhat
bhat

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
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
Avatar of gurukg102498

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial