Disable the Close system menu for MDI child window

How can I disable the Close ("x") button of the MDI child window ?

I tried to add the following code in the OnCreate virtual function of my child frame class:

CMenu * psysmenu = GetSystemMenu( FALSE );

It worked as long as the child window is not maximized, but if the child window is maximized then the "x" button is not disabled.
Who is Participating?
galkinConnect With a Mentor Commented:
You must resiter your window class with style CS_NOCLOSE. If you use MFC overwrite your frame PreCreateWindow and register new class by calling AfxRegisterWndClass(CS_NOCLOSE);. You can add other styles using bitwise OR operator. then assign class name returned by AfxRegisterWndClass to lpszClass field of CREATESTRUCT structure and call base class PreCreateWindow implementation.
Tommy HuiEngineerCommented:
You can try catching the WM_SYSCOMMAND and checking if (WPARAM & SC_CLOSE) == SC_CLOSE. If it is, then don't call the base class.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.