Creating an SDI app without a menu bar...
Mark Johnson -- MJohnson@ixc-comm.net Wednesday, February 19, 1997 Environment: VC4.2-flat, NT 4.0 Is is possible to create an SDI application without a menu bar but with a tool bar? I tried simply deleting the MENU resource that was generated by the AppWizard, yet i kept the toolbar resource. However, running the application causes the following error. "Failed to create empty document." What i'm trying to do is create an SDI application with a PropertySheet in the View and provide only a tool bar and status bar. any suggestions? thanks, mark.
Andrew Fomichev -- andrewf@MICROSOFT.com Thursday, February 20, 1997 Override your mainframe window's PreCreateWindow() function and specify a zero menu handle: BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { cs.hMenu = NULL; return CFrameWnd::PreCreateWindow(CREATESTRUCT& cs); } Andy > ---------- > From: Mark Johnson[SMTP:MJohnson@ixc-comm.net] > Sent: Wednesday, 19 February, 1997 15:50 > To: 'mfc-l@netcom.com' > Subject: Creating an SDI app without a menu bar... > > Environment: VC4.2-flat, NT 4.0 > > Is is possible to create an SDI application without a menu bar but > with > a tool bar? I tried simply deleting the MENU resource > that was generated by the AppWizard, yet i kept the toolbar resource. > However, running the application causes the following error. > > "Failed to create empty document." > > What i'm trying to do is create an SDI application with a > PropertySheet > in the View and provide only a tool bar and status bar. > > any suggestions? > > thanks, mark. > >
bshamsian@ccvhs.vhsla.com Thursday, February 20, 1997 Mark Yes there is... >From Microsoft Knowledge base: --------------------------------------------------------------------------- How to Create MFC Applications That Do Not Have a Menu Bar Article ID: Q131368 Revision Date: 17-JAN-1996 The information in this article applies to: - The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++ for Windows, versions 1.5, 1.51, 1.52 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 2.1, and 4.0 SUMMARY For most Windows-based applications, a menu bar is a part of the user interface. The menu bar provides a functionality summary for the person using the program. However, it is not required that every Windows-based application must contain a menu bar. This article describes how to create an MFC application that does not have a menu bar. For Windows-based applications generated by AppWizard, the IDR_MAINFRAME menu resource is the standard menu resource for both SDI and MDI applications. It is the only menu resource for an SDI application. MDI applications contain additional menus for each type of MDI child window they support. Those menu resources are usually named IDR_xxxTYPE, where xxx is related to the name of the corresponding document type. Thus, creating an application with no menus is not as easy for an MDI application as for an SDI application. You basically have to modify all functions related to loading and switching menus. MORE INFORMATION Steps to Create SDI Application That Has No Menu Bar 1. Generate an SDI 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. 2. To prevent the main application window from having a menu bar, delete the already loaded menu, and set the hMenu field of the CREATESTRUCT structure to NULL in the CFrameWnd::PreCreateWindow() function: 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 CFrameWnd::PreCreateWindow(cs); } Steps to Create MDI Application That Has No Menu Bar 1. 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. 2. Delete menu resources associated with MDI child windows (IDR_xxxTYPE). They are not used. By deleting them, you avoid a resource (memory) leak. 3. 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); } 4. 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); } ______________________________ Reply Separator _________________________________ Subject: Creating an SDI app without a menu bar... Author: mfc-l@netcom.com at vhsunix Date: 2/20/97 7:20 PM Environment: VC4.2-flat, NT 4.0 Is is possible to create an SDI application without a menu bar but with a tool bar? I tried simply deleting the MENU resource that was generated by the AppWizard, yet i kept the toolbar resource. However, running the application causes the following error. "Failed to create empty document." What i'm trying to do is create an SDI application with a PropertySheet in the View and provide only a tool bar and status bar. any suggestions? thanks, mark.
Become an MFC-L member | Вернуться в корень Архива |