Your C-language code undoubtedly contains logic to enable and disable your program's menus depending on the program's current state. In order to make that code work in MFC, you need to disable MFC's mechanism for managing menu-item states.
When the user pulls down a menu, MFC searches for "update handlers" for the items on that menu, using the MFC message map. MFC performs this search before the menu drops down, so by the time the user sees the menu, its items have been appropriately enabled, disabled, checked, or unchecked. If MFC finds a handler for a menu item, it calls the handler to set the menu item's state. If there is no update handler associated with the command ID for a menu item, MFC disables the menu item by default. If you build your application at this stage, before bypassing the MFC mechanism, all of your menus will be grayed.
The following is an example of an update handler from another application:
void CScribDoc::OnUpdateEditClearAll(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_strokeList.IsEmpty()); }
In the example, the update handler accesses an Edit Clear All command through the CCmdUI object passed to it. Calling the object's Enable member function takes care of enabling or disabling any user interface object — such as a menu item or toolbar button — associated with the command ID for that command.
Fortunately, disabling the menu update mechanism is easy. Just add the following line of code to the constructor for class CMainFrame (in MAINFRM.CPP):
CMainFrame::CMainFrame() { m_bAutoMenuEnable = FALSE; // bypass MFC menu enabling mechanism }
Now MFC relies entirely on your code to enable menu items. (Do this in CMainFrame rather than the view; the CFrameWnd::m_bAutoMenuEnable variable is easier to access there.)
For SHOWDIB, disable menu updating as shown above.
Note When memory is allocated for a C++ class object, the object's "constructor" is called. The constructor is a special function with the same name as the class. The constructor is normally used to initialize the object's allocated memory.
Just before a C++ object is destroyed, the object's "destructor" is called to clean up. The destructor is often used to deallocate any resources, such as memory, that were allocated by the constructor. The destructor has the same name as the class, prefixed with a tilde (~).
If you don't specify a constructor or destructor in your own classes, C++ supplies default versions, which may or may not do what you want.