?
Solved

How to unable window Close Button at MFC???

Posted on 2004-11-02
5
Medium Priority
?
445 Views
Last Modified: 2013-11-20
CMenu* systemMenu = GetSystemMenu(false);

if(systemMenu)
{
     systemMenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_DISABLED);
}


Above coding, i found that cannot function at OnInitialUpdate().

Is it got any problem abouth this shot?

I would like to unable  window close button when my program load...

TQ!
0
Comment
Question by:DannyGan9
5 Comments
 
LVL 5

Expert Comment

by:Nass89
ID: 12480415
Hi,
What is "systemMenu"?
Just add the following line to OnInitDialog() and the close button will be disabled.

BOOL CDlg9Dlg::OnInitDialog()
{
...
...

      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
            CString strAboutMenu;
            strAboutMenu.LoadString(IDS_ABOUTBOX);
            if (!strAboutMenu.IsEmpty())
            {
                  pSysMenu->AppendMenu(MF_SEPARATOR);
                  pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
            }
// Add here
            pSysMenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_DISABLED);
      }
...
...
}

Good Luck!
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 12480464
EnableMenuItem is CView class. View doesn't have system menu, GetSystemMenu returns NULL. You need to move this code to the frame class, and use another message handler, like WM_CREATE.
0
 

Author Comment

by:DannyGan9
ID: 12480633
So what is the right way to enable the window close button????

TQ!
0
 
LVL 5

Expert Comment

by:Nass89
ID: 12481085
Hi,
The codes are for dialog based view? Which class are you using?
MDI or SDI or Dialog?
0
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 400 total points
ID: 12488907
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CMDIFrameWnd::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;      // fail to create
      }

      if (!m_wndStatusBar.Create(this) ||
            !m_wndStatusBar.SetIndicators(indicators,
              sizeof(indicators)/sizeof(UINT)))
      {
            TRACE0("Failed to create status bar\n");
            return -1;      // fail to create
      }

      // TODO: Delete these three lines if you don't want the toolbar to
      //  be dockable
      m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
      EnableDocking(CBRS_ALIGN_ANY);
      DockControlBar(&m_wndToolBar);
      CMenu *pmenu = GetSystemMenu(FALSE);
      pmenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_DISABLED|MF_GRAYED);
      return 0;
}
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question