刪除MFC單文件預設選單欄的兩種方法

2021-05-22 09:20:36 字數 1954 閱讀 7509

新建乙個mfc單文件程式,預設都有四個選單欄:檔案、編輯、檢視和幫助。怎麼把這四個選單欄刪除掉呢?有兩種方法:

第一種方法:過載框架類的create函式,具體**如下:

view plaincopy to clipboardprint?

bool cmainframe::create(lpctstr lpszclassname, lpctstr lpszwindowname, dword dwstyle , const rect& rect , cwnd* pparentwnd , lpctstr lpszmenuname , dword dwexstyle , ccreatecontext* pcontext)  

bool cmainframe::create(lpctstr lpszclassname, lpctstr lpszwindowname, dword dwstyle , const rect& rect , cwnd* pparentwnd , lpctstr lpszmenuname , dword dwexstyle , ccreatecontext* pcontext)

第二種方法:手動刪除所有選單項。具體是先定義乙個刪除所有選單項的函式:

view plaincopy to clipboardprint?

/*! 

*  /brief 刪除所有的選單欄。 

*  * 刪除視窗的所有選單欄。 

*  /return 無。 

*/ 

static void delallmenu(hmenu hmenu)  

}  /*!

*  /brief 刪除所有的選單欄。

** 刪除視窗的所有選單欄。

*  /return 無。

*/static void delallmenu(hmenu hmenu)

} 然後在框架類的oncreate函式呼叫這個函式,具體如下:

view plaincopy to clipboardprint?

int cmainframe::oncreate(lpcreatestruct lpcreatestruct)  

if (!m_wndstatusbar.create(this) ||  

!m_wndstatusbar.setindicators(indicators,  

sizeof(indicators)/sizeof(uint)))  

// todo: 如果不需要工具欄可停靠,則刪除這三行  

m_wnd*******.enabledocking(cbrs_align_any);  

enabledocking(cbrs_align_any);  

dockcontrolbar(&m_wnd*******);  

// 獲取視窗的選單控制代碼  

cmenu *pmenu = getmenu();  

if (null!=pmenu)  

return 0;  

}  int cmainframe::oncreate(lpcreatestruct lpcreatestruct)

if (!m_wndstatusbar.create(this) ||

!m_wndstatusbar.setindicators(indicators,

sizeof(indicators)/sizeof(uint)))

// todo: 如果不需要工具欄可停靠,則刪除這三行

m_wnd*******.enabledocking(cbrs_align_any);

enabledocking(cbrs_align_any);

dockcontrolbar(&m_wnd*******);

// 獲取視窗的選單控制代碼

cmenu *pmenu = getmenu();

if (null!=pmenu)

return 0;

}

刪除MFC單文件預設選單欄的兩種方法

第一種方法 過載框架類的create函式,具體 如下 bool cmainframe create lpctstr lpszclassname,lpctstr lpszwindowname,dword dwstyle const rect rect cwnd pparentwnd lpctstr l...

刪除MFC單文件預設選單欄的兩種方法

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!第一種方法 過載框架類的create函式,具體 如下 cpp view plain copy print?bool cmainframe create lpctstr lpszclassname,lpctstr lpszwindowname,dwo...

MFC 單文件去掉標題欄和選單欄

隱藏標題欄 在cmainframe的oncreate 中新增如下 方法一 好用 long style 去掉標題欄及其他樣式 setwindowlong this m hwnd,gwl style,0 去掉邊框及其他樣式 setwindowlong this m hwnd,gwl exstyle,0 ...