Link to home
Start Free TrialLog in
Avatar of DannyGan9
DannyGan9

asked on

How to unable window Close Button at MFC???

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!
Avatar of Nass89
Nass89
Flag of United States of America image

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!
Avatar of AlexFM
AlexFM

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.
Avatar of DannyGan9

ASKER

So what is the right way to enable the window close button????

TQ!
Hi,
The codes are for dialog based view? Which class are you using?
MDI or SDI or Dialog?
ASKER CERTIFIED SOLUTION
Avatar of OnegaZhang
OnegaZhang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial