For some cases of running VC program, there will be no user through the title bar on the Close button to close the window, you will find that this time the program's Turn off button turned gray is not available, from the taskbar can not close the window, the menu is also gray, very good to prohibit the window off function, if you want to close, You can press the shortcut key "Alt+f4" on your keyboard or end a task through Task Manager. Here is a description of the core code file for this feature.
The specific function code to disable the Close button is as follows:
#include "stdafx.h" #include "Test.h" #include "MainFrm.h" #ifdef _DEBUG #define NEW debug_new #endif//CMainFrame IMPL
Ement_dyncreate (CMainFrame, CFrameWnd) begin_message_map (CMainFrame, CFrameWnd) on_wm_create () End_message_map ()
Static UINT indicators[] = {id_separator,//Status row indicator Id_indicator_caps, Id_indicator_num, ID_INDICATOR_SCRL,}; CMainFrame Construct/Destroy Cmainframe::cmainframe () {//TODO: Add member initialization code in here} cmainframe::~cmainframe () {} int cmainframe::o
Ncreate (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 a 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: If the toolbar is not required to dock, delete the three rows m_wndtoolbar.enabledocking (Cbrs_align_any);
EnableDocking (Cbrs_align_any);
DockControlBar (&m_wndtoolbar);
Obtain the System menu CMenu *pmenu=getsystemmenu (FALSE);
Get the System menu quantity int count=pmenu->getmenuitemcount ();
Gets the ID of the Shutdown menu UINT id=pmenu->getmenuitemid (Count-1);
Prohibit off menu Pmenu->enablemenuitem (id,mf_grayed);
return 0; BOOL CMainFrame::P Recreatewindow (createstruct& cs) {if (!
CFrameWnd::P Recreatewindow (CS)) return FALSE;
TODO: Modify the window class or//Style return TRUE by modifying the CREATESTRUCT CS here;
}//CMainFrame diagnostics #ifdef _DEBUG void Cmainframe::assertvalid () const {cframewnd::assertvalid ();}
void CMainFrame::D UMP (cdumpcontext& DC) const {CFrameWnd::D UMP (DC);} #endif//_debug//CMainFrame message handlers