how to prevent a mdi child from closing?

how to prevent a mdi child from closig? i have tried disable the WS_SYSMENU but a chlid can still be closed by ctrl-f4.

thanks.
bunwongAsked:
Who is Participating?
 
MadYugoslavConnect With a Mentor Commented:
Override mesage handler for message WM_CLOSE.
0
 
Meir RivkinFull stack Software EngineerCommented:
u mean alt+F4, not Ctrl+F4

0
 
MichaelSCommented:
Set CS_NOCLOSE window style for you child window
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Meir RivkinFull stack Software EngineerCommented:
override WindowProc() as follow:
LRESULT WindowProc(
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
);



LRESULT CDynamicControlsDlg::WindowProc(UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
     if(uMsg == WM_CLOSE)
          return 0;

     return CDialog::WindowProc(uMsg,wParam,lParam);
}

good luck
0
 
Meir RivkinFull stack Software EngineerCommented:
sorry, for child frame its should look like this:
LRESULT CChildFrame::WindowProc(UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
    if(uMsg == WM_CLOSE)
         return 0;

    return CMDIChildWnd::WindowProc(uMsg,wParam,lParam);
}

btw, when u press ALT+F4 the main frame receives the WM_CLOSE and shut down the application so u need to take this under consideration
0
 
bunwongAuthor Commented:
it works, i am amazed how simple it is. thanks MadYugoslav
0
 
MadYugoslavCommented:
Thanks.
0
 
MichaelSCommented:
>it works
yep, it works but how :)
user see the close button, press it and nothing happens. or even better, user can do nothing, no minimize, no maximaze.

The solution I proposed allows you to have close button but it's disabled and from that point it's clear that window can't be closed
0
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.