VC implementation of the Turn off button into a gray unavailable method _c language

Source: Internet
Author: User

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

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.