15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Disable CView closing

Vincent Mascart -- 100425.1337@compuserve.com
Monday, March 04, 1996

Hi all,

I have an MDI application with one view I don't want the be closed by the user.

I already disabled the close item in the system menu doing:

	pWnd = (CMDIChildWnd*)GetParentFrame();
	pMenu = pWnd->GetSystemMenu(FALSE);
	pMenu->EnableMenuItem(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);

It's perfect for mouse input, but the keyboard shortcut CTRL+F4 still close the
view.

I tryied to trap SC_CLOSE in OnSysCommand() at the CView level and at the
CMDIChildWnd level but none of these works.

Help is welcome.

Vincent Mascart
Little Indian sprl.
100425.1337@compuserve.com




Jean-Francois Cordier -- cordierj@chor.ucl.ac.be
Wednesday, March 06, 1996

At 17:25 04/03/1996 EST, you wrote:
>Hi all,
>
>I have an MDI application with one view I don't want the be closed by the user.
>
>I already disabled the close item in the system menu doing:
>
>	pWnd = (CMDIChildWnd*)GetParentFrame();
>	pMenu = pWnd->GetSystemMenu(FALSE);
>	pMenu->EnableMenuItem(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
>
>It's perfect for mouse input, but the keyboard shortcut CTRL+F4 still close the
>view.
>
>I tryied to trap SC_CLOSE in OnSysCommand() at the CView level and at the
>CMDIChildWnd level but none of these works.
>
>Help is welcome.
>

Why just don't you override OnClose() of your CView parent frame ?????

I did it for my CFormView's and it worked fine (I even add a
ShowWindow(SW_SHOWMINIMIZED) when close was disabled):

void CMyFrame::OnClose()
{
  if (no_close) 
  {
    ShowWindow(SW_MINIMIZE);
    return; // don't close this frame
  }
  CEndChildFrame::OnClose();
}

The simpliest the best....


Dji.
--------------------------------------------------------------------------
Jean-Francois Cordier (a.k.a. Dji)    Office : +32 10 47.87.58
Universite Catholique de Louvain      Home   : +32 10 45.60.18
Laboratoire ORSY                      Fax    : +32 10 47.20.48/41.68
1, pl. L. Pasteur                     WWW    : http://c227b.chor.ucl.ac.be/
1348 Louvain-la-Neuve (BELGIUM)       Email  : cordierj@chor.ucl.ac.be






Frederic Steppe -- FredericS@msn.com
Wednesday, March 06, 1996

Hi Vincent,

did you try to trap the WM_CLOSE message (CWnd::OnClose) and just do nothing 
if you don't want the windows to be closed (default implementation calls 
DestroyWindow) ?

Fred.



Jean-Francois Cordier -- cordierj@chor.ucl.ac.be
Thursday, March 07, 1996

At 16:55 06/03/1996 UT, you wrote:
>Hi Vincent,
>
>did you try to trap the WM_CLOSE message (CWnd::OnClose) and just do nothing 
>if you don't want the windows to be closed (default implementation calls 
>DestroyWindow) ?
>
>Fred.
>
I think he must override the CFrameWnd::OnClose() handler and not the
CView's one. If I'm right, from what I got when I added a TRACE in both
handlers (CView & CFrameWnd), CView::OnClose() is called after
CFrameWnd::OnClose(), the CFrameWnd will be destroyed but one of it's view
will still be there...

I may be mistaken tough... :-{

Dji.




Mario Contestabile -- Mario_Contestabile.UOS__MTL@UOSMTL2.universal.com
Thursday, March 07, 1996

[Mini-digest: 2 responses]

[Snip->Start()*********************************]
>I have an MDI application with one view I don't want the be closed by the user.
>
>I already disabled the close item in the system menu doing:
>
> pWnd = (CMDIChildWnd*)GetParentFrame();
> pMenu = pWnd->GetSystemMenu(FALSE);
> pMenu->EnableMenuItem(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
>
>It's perfect for mouse input, but the keyboard shortcut CTRL+F4 still close the
>view.
>
>I tryied to trap SC_CLOSE in OnSysCommand() at the CView level and at the
>CMDIChildWnd level but none of these works.
>
>Help is welcome.
>

Why just don't you override OnClose() of your CView parent frame ?????

I did it for my CFormView's and it worked fine (I even add a
ShowWindow(SW_SHOWMINIMIZED) when close was disabled):

void CMyFrame::OnClose()
{
  if (no_close) 
  {
    ShowWindow(SW_MINIMIZE);
    return; // don't close this frame
  }
[Snip->End()************************************************]

MSVC 4.0/NT & 95

While we're on the subject of "Disabling the closure", I recently has the 
opportunity
of having to prevent the last document from getting closed. There were two 
steps involved,
disabling the mainframe menu option "Close", and disabling the document's 
"Close" option.
Disabling the menu was easy, I used an update command handler for ID_FILE_CLOSE
and in it pCmdUI->Enable(False if last document). The code snippet above is 
another method.
The second step involved disabling the documents own close option. In my 
CMDIChildWnd
derived class I wrote a handler for OnInitMenuPopup(). That gets called every 
time the user
activates the document's menu. There I call EnableMenuItem(False if last 
document).
Perfect, all went well (on NT that is). Alas Win95. You know how Win95 has a 
little "X" in the top right corner
to close a window? Yup, now this is a third step. What currently happens is
when there is one document, the main menu option is correctly disabled; The 
document's
menu close option is also correctly disabled, but it is disabled when it is 
*activated*. Only then will the "X" be
grayed out. But if you never activate its menu, you can still close the 
document by hiting
the "X"! Even if you somehow disable the  close option upon the documents 
creation,
it needs to be reactivated when opening new documents...

Has anyone achieved this behavior? If so, how?

mcontest@universal.com

-----From: Vincent Mascart <100425.1337@compuserve.com>

Of course !

I don't know why, but I absolutely wanted to trap the WM_CLOSE at the CView
derived class level, and of course I never got it.

You know, sometimes things are too obvious ...

Thanks for your help.

Vincent





| Вернуться в корень Архива |