Solved

MDI form

Posted on 2000-04-13
10
250 Views
Last Modified: 2013-11-20
Hi,
   I am creating an MDI form,but i dont want the menu to be there in my application. Is it possible to do this? I am connecting my application to a database, but i want to achieve it without menus

Thanx,
Thiru
0
Comment
Question by:thirumaran
  • 5
  • 4
10 Comments
 
LVL 5

Expert Comment

by:proskig
Comment Utility
Steps to Create MDI Application that Has No Menu Bar
Generate an MDI application with AppWizard. Do not delete the IDR_MAINFRAME menu resource. If you have an application that was not generated with AppWizard, do not delete the corresponding main menu resource. Leaving the menu resource is required to avoid assertion failures in the MFC code.


Delete menu resources associated with MDI child windows (IDR_xxxTYPE). They are not used. By deleting them, you avoid a resource (memory) leak.


Override the PreCreateWindow() function for the CMainFrame class:

      BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
      {
         if(cs.hMenu!=NULL)
         {
             ::DestroyMenu(cs.hMenu);      // delete menu if loaded
             cs.hMenu = NULL;              // no menu for this window
         }

         return CMDIFrameWnd::PreCreateWindow(cs);
      }



Modify the code responsible for switching menus by overriding the LoadFrame() and OnCreateClient() methods of CMainFrame. This is necessary because MFC has already loaded and switched menus automatically. The following shows what must be done:

      // Overridden method declarations for CMainFrame

      BOOL LoadFrame( UINT nIDResource,
             DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
             CWnd* pParentWnd = NULL, CCreateContext* pContext = NULL );
      BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,
             CCreateContext* /*pContext*/);

      // Overridden method declarations for CMainFrame

      BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
             CWnd* pParentWnd, CCreateContext* pContext)
      {
          return CFrameWnd::LoadFrame(nIDResource,dwDefaultStyle,
              pParentWnd,pContext);
      }

      BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,
              CCreateContext* /*pContext*/)
      {
          return CreateClient(lpcs,NULL);
      }



NOTE: Instead of calling the base class (CMDIFrameWnd) in the override of LoadFrame, you call its base class, CFrameWnd, instead. That way you can avoid the code that deals with MDI menus.
0
 

Author Comment

by:thirumaran
Comment Utility
It is showing application error when this code is implemented.

Thiru
0
 
LVL 5

Expert Comment

by:proskig
Comment Utility
Where? What is the error?
0
 

Author Comment

by:thirumaran
Comment Utility
where to put the declarations fo the member functions LoadFrame and OnCreateClient.What are the access specifiers??Is it in MainFrame.h and the definition in .cpp file?

Thanx,
Thiru
0
 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
Hi,

U can use SetMenu(NULL) in the mainframe.
try it out.

VinExpert
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:thirumaran
Comment Utility
where to put the declarations fo the member functions LoadFrame and OnCreateClient.What are the access specifiers??Is it in MainFrame.h and the definition in .cpp file?

Thanx,
Thiru
0
 
LVL 5

Accepted Solution

by:
proskig earned 25 total points
Comment Utility
Yes,
by default files are MainFrame.h and MainFrame.cpp. These functions are virtual and public. The best way to add them is to use ClassWizard.
0
 

Author Comment

by:thirumaran
Comment Utility
The error is shown in windows.cpp file , where theLoadFrame takes only 1 parameter,instead of 4 parameters.

Thanx,
Thiru
0
 
LVL 5

Expert Comment

by:proskig
Comment Utility
LoadFrame is the member of CMainFrame - it is not global one. Can you send me your code by E-Mail - it will be easier.
proskig@hotmail.com
0
 

Author Comment

by:thirumaran
Comment Utility
My code is working now. Thanx for ur help proskig

Thiru
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 149
Tab names are off by one 5 49
sumDigits challenge 9 95
Problem to open Excel file 15 37
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now