[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

opening a document without a menu

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
Ashurbanipal
Asked:
Ashurbanipal
  • 7
  • 6
  • 4
1 Solution
 
AlexNekCommented:
m_pSimTemplate->CreateNewDocument( );
0
 
AshurbanipalAuthor Commented:
If I use

 m_pSimTemplate->CreateNewDocument( );

how do I set these values:

   RUNTIME_CLASS(CSimEditDoc),
    RUNTIME_CLASS(CMainFrame),
    RUNTIME_CLASS(CSimEditView));
0
 
CriusCommented:
You already did when you said m_pSimTemplate = new CSingleDocTemplate(
       0,
    RUNTIME_CLASS(CSimEditDoc),
    RUNTIME_CLASS(CMainFrame),
    RUNTIME_CLASS(CSimEditView));
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AlexNekCommented:
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
 
CriusCommented:
He's using 0 because he doesn't want a menu for the document.
0
 
CriusCommented:
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
 
AlexNekCommented:
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
 
CriusCommented:
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
 
AlexNekCommented:
2 Crius
It is only kind of lottery :))
0
 
AshurbanipalAuthor Commented:
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
 
CriusCommented:
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
 
AlexNekCommented:
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
 
CriusCommented:
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
 
AshurbanipalAuthor Commented:
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
 
AlexNekCommented:
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
 
CriusCommented:
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
 
AshurbanipalAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now