Solved

opening a document without a menu

Posted on 2002-05-17
17
541 Views
Last Modified: 2013-11-20
How do I create a document withou a menu?  The following code generates an assertion error for the resource id:

m_pSimTemplate = new CSingleDocTemplate(
        0,
     RUNTIME_CLASS(CSimEditDoc),
     RUNTIME_CLASS(CMainFrame),
     RUNTIME_CLASS(CSimEditView));


thanks,
0
Comment
Question by:Ashurbanipal
  • 7
  • 6
  • 4
17 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 7016563
m_pSimTemplate->CreateNewDocument( );
0
 

Author Comment

by:Ashurbanipal
ID: 7016872
If I use

 m_pSimTemplate->CreateNewDocument( );

how do I set these values:

   RUNTIME_CLASS(CSimEditDoc),
    RUNTIME_CLASS(CMainFrame),
    RUNTIME_CLASS(CSimEditView));
0
 
LVL 3

Expert Comment

by:Crius
ID: 7017089
You already did when you said m_pSimTemplate = new CSingleDocTemplate(
       0,
    RUNTIME_CLASS(CSimEditDoc),
    RUNTIME_CLASS(CMainFrame),
    RUNTIME_CLASS(CSimEditView));
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7017450
2 Ashurbanipal
why you use 0?
Create your project with the wizard. Then you will have correct resources and ids

m_pSimTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CSimEditDoc),
    RUNTIME_CLASS(CMainFrame),
    RUNTIME_CLASS(CSimEditView)
);



0
 
LVL 3

Expert Comment

by:Crius
ID: 7017471
He's using 0 because he doesn't want a menu for the document.
0
 
LVL 3

Accepted Solution

by:
Crius earned 50 total points
ID: 7017472
He is right though. A 0 does cause an assertion. Did the question change on me? I must be losing it, because I've been trying to answer the wrong question all along. :p
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7017504
2 Crius
>A 0 does cause an assertion
You are right. 0 really create the assertion.
// 0000 -> 7FFF IDR range
// 0000 -> 6FFF : user resources
// 7000 -> 7FFF : AFX (and standard windows) resources
// IDR ranges (NOTE: IDR_ values must be <32768)
#define ASSERT_VALID_IDR(nIDR) ASSERT((nIDR) != 0 && (nIDR) < 0x8000)

2 Ashurbanipal
Please pay attention that IDR_MAINFRAME is:
Accelerator ID
Menu ID
Icon ID
String ID
Toolbar ID (can be)



0
 
LVL 3

Expert Comment

by:Crius
ID: 7025539
I hate to be a nitpicker, but I don't know the answer to this question... How'd I get the points?

Did the question get solved somehow?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:AlexNek
ID: 7025572
2 Crius
It is only kind of lottery :))
0
 

Author Comment

by:Ashurbanipal
ID: 7025593
You guys tried to be helpful.  Apparently the asserts are bogus because the run-time version works fine.

I don't like leaving questions hanging around so I just did the "kind of lottery".  That's all.

Thanks
0
 
LVL 3

Expert Comment

by:Crius
ID: 7025675
Ah, well, the Release version of an executable does not use ASSERTs.

Basically, ASSERT is #ifdef right out of existance unless DEBUG is defined, so, the Release version wouldn't crash, but debug will.

However, In the MSDN library, I found the solution under Q131368 - HOWTO: Create MFC Applications that Do Not Have a Menu Bar.
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7026556
It is a pity but I read the question as "CREATE a document withou a menu" not as "Applications that
Do Not Have a Menu Bar"
0
 
LVL 3

Expert Comment

by:Crius
ID: 7027463
Did you read Q131368? It explains how to remove the menu at runtime with no problems. You can do it for any view/document in an MDI, or the main SDI window. I read Q131368, and it works perfectly for answering this question.
0
 

Author Comment

by:Ashurbanipal
ID: 7027682
I went to MSDN online, but couldn't fine Q131368.  Even on a search of the entire msdn.  I seen that terminology before, but can't remember how to get to that area.  What's the trick?
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7028134
MSDN CD kbvc.chm::/Source/visualc/q131368.htm
Steps to Create SDI Application that Has No Menu Bar
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.


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
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
 
LVL 3

Expert Comment

by:Crius
ID: 7028225
The problem is, this is a HOWTO. BUGS, HOWTO, and other *knowledge base* articles, although that are included in the CD Version of the MSDN library, are not actually part of the MSDN Online library. So, you won't find it on msdn.microsoft.com.

All the knowledge base articles are available at support.microsoft.com.

So, to find this topic, you'd go to support.microsoft.com, and search for Q131368.

All Q* topics are knowledge base articles, so that's how you can tell the difference. :)
0
 

Author Comment

by:Ashurbanipal
ID: 7028296
It works fine, thanks.

I have the msdn cd library, but searches in it don't turn up q131368.  Going into the contents and going through the bugs might turn it up.  I would think there would some easy search mechanism.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

21 Experts available now in Live!

Get 1:1 Help Now