Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

opening a document without a menu

Posted on 2002-05-17
17
545 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 117
Detect CR LF to each line 12 169
sum13 challenge 24 121
wordappend challenge 8 200
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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