Link to home
Start Free TrialLog in
Avatar of bunwong
bunwong

asked on

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.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

u mean alt+F4, not Ctrl+F4

ASKER CERTIFIED SOLUTION
Avatar of MadYugoslav
MadYugoslav
Flag of Serbia image

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
Avatar of MichaelS
MichaelS

Set CS_NOCLOSE window style for you child window
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
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
Avatar of bunwong

ASKER

it works, i am amazed how simple it is. thanks MadYugoslav
Thanks.
>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