asp.net two ways to remove the MFC single document default menu bar
- 2020-05-09 18:29:26
- OfStack
There are two ways:
Method 1: overloading the Create function of the framework class. The code is as follows:
Option 2: manually delete all menu items. To be specific, first define a function to delete all menu items:
Then call this function in the OnCreate function of the framework class, as follows:
Method 1: overloading the Create function of the framework class. The code is as follows:
BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle , const RECT& rect , CWnd* pParentWnd , LPCTSTR lpszMenuName , DWORD dwExStyle , CCreateContext* pContext)
{
// TODO: Add dedicated code and here / Or call the base class
// return CFrameWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, // //pParentWnd, lpszMenuName, dwExStyle, pContext);
HMENU nIDorHMenu = NULL;
return CFrameWnd::CreateEx(dwExStyle,lpszClassName,lpszWindowName,dwStyle,
rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,
pParentWnd->GetSafeHwnd(),
nIDorHMenu,
(LPVOID)pContext);
}
Option 2: manually delete all menu items. To be specific, first define a function to delete all menu items:
/*!
* \brief Delete all menu bars.
*
* Delete all menu bars from the window.
* \return No.
*/
static void DelAllMenu(HMENU hMenu)
{
// First remove the redundant menu items
int Menucount = GetMenuItemCount(hMenu);
for (int i = Menucount-1;i>-1;i--)
{
::DeleteMenu(hMenu,i, MF_BYPOSITION);
}
}
Then call this function in the OnCreate function of the framework class, as follows:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0(" Could not create toolbar \n");
return -1; // Failed to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0(" Failed to create status bar \n");
return -1; // Failed to create
}
// TODO: Delete this if you do not need the toolbar to dock 3 line
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// Gets the menu handle to the window
CMenu *pMenu = GetMenu();
if (NULL!=pMenu)
{
DelAllMenu(pMenu->GetSafeHmenu());
}
return 0;
}