asp.net two ways to remove the default menu bar for an MFC Single document _ Practical Tips

Source: Internet
Author: User
There are two ways of doing this:

The first method: Overload the CREATE function of the frame class, as follows:
Copy Code code as follows:

BOOL cmainframe::create (LPCTSTR lpszclassname, LPCTSTR lpszwindowname, DWORD dwstyle, const rect& RECT, CWnd* PParen Twnd, LPCTSTR lpszmenuname, DWORD dwExStyle, ccreatecontext* pContext)
{
TODO: Add private code here and/or call base class
Return CFrameWnd::Create (lpszClassName, lpszWindowName, Dwstyle, rect,////pparentwnd, Lpszmenuname, DwExStyle, PCo ntext);
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);
}

The second method: Manually delete all menu items. Define a function that deletes all menu items first:
Copy Code code as follows:

/*!
* \brief Delete all the menu bars.
*
* Delete all menu bars for the window.
* \return No.
*/
static void Delallmenu (Hmenu hmenu)
{
First remove the extra menu items
int menucount = Getmenuitemcount (hmenu);
for (int i = menucount-1;i>-1;i--)
{
::D Eletemenu (Hmenu,i, mf_byposition);
}
}

This function is then called in the OnCreate function of the framework class, as follows:
Copy Code code 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 ("Failed to create toolbar \ n");
return-1; Failed to create
}
if (!m_wndstatusbar.create) | |
!m_wndstatusbar.setindicators (indicators,
sizeof (indicators)/sizeof (UINT))
{
TRACE0 ("Failed to create status bar \ n");
return-1; Failed to create
}
TODO: Delete These three lines if you don't need the toolbar to dock
M_wndtoolbar.enabledocking (Cbrs_align_any);
EnableDocking (Cbrs_align_any);
DockControlBar (&m_wndtoolbar);
Get a menu handle for a window
CMenu *pmenu = GetMenu ();
if (Null!=pmenu)
{
Delallmenu (Pmenu->getsafehmenu ());
}
return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.