473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Preventing an MDI child from being closed

I would like to prevent the user from closing MDI child windows. However, I
would like them to be able to minimize and maximize them.

Setting the Control Box to false removes the minimize and maximize too.

An obvious thing to do is to handling the CLosing event and cancel it.
Sadly, if you do this the main Form refuses to shut down...

A solution to this is to intercept the Closing event on the main form and
use it to set a boolean that the children can check to see if they CAN close
down.

But this is raised *after* the childrens events.

Hmmm.

Any one know how I can sort this out?

Iain
Nov 15 '05 #1
5 4292
"Iain" <id********@dircon.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I would like to prevent the user from closing MDI child windows. However, I would like them to be able to minimize and maximize them.

Setting the Control Box to false removes the minimize and maximize too.

An obvious thing to do is to handling the CLosing event and cancel it.
Sadly, if you do this the main Form refuses to shut down...

A solution to this is to intercept the Closing event on the main form and
use it to set a boolean that the children can check to see if they CAN close down.

But this is raised *after* the childrens events.


As a user I would be offended by you inhibiting me from closing the MDI
child. If you don't want me to close a child, the close option should be
disabled. It would be wrong to offer the close option, accept the command
and than fail to comply.

MDI has practically been deprecated for some time now, Microsoft does not
encourage to use it.

In an MDI application, all MDI Windows should contain documents of the same
type. If you are presenting different types in different MDI windows, MDI
does not apply and it should not be used.

If you are showing singleton documents/objects of different types in MDI
child windows and you were to ignore my valuable advise to not abuse the MDI
model, you could make the result less annoying on the user by accepting the
close command and hiding the child instead of closing it. The MDI window's
View menu could them offer a list of views that can be checkmarked in order
to make them visible or hide them. Close on a child would be the shortcut
for going into the menu and hiding it.

Martin.
Nov 15 '05 #2
Thanks for your comments, Martin.

The MDI format suits the application I have built which has a number of
'management consoles'. I don't much care if MS do not approve! (I could
argue if pressed that they are each simply a view of the underlying
database).

There appears no way of disabling only the close box. Certainly not without
disabling the minimize and maximize.

Even if I picked a hide rather than close option, I suspect I would still be
unable to close the application. After all to hide the window I would have
to cancel the close which seems to have the effect of cancelling the main
window close.

Any other thoughts?

Iain
As a user I would be offended by you inhibiting me from closing the MDI
child. If you don't want me to close a child, the close option should be
disabled. It would be wrong to offer the close option, accept the command
and than fail to comply.

MDI has practically been deprecated for some time now, Microsoft does not
encourage to use it.

In an MDI application, all MDI Windows should contain documents of the same type. If you are presenting different types in different MDI windows, MDI
does not apply and it should not be used.

If you are showing singleton documents/objects of different types in MDI
child windows and you were to ignore my valuable advise to not abuse the MDI model, you could make the result less annoying on the user by accepting the close command and hiding the child instead of closing it. The MDI window's
View menu could them offer a list of views that can be checkmarked in order to make them visible or hide them. Close on a child would be the shortcut
for going into the menu and hiding it.

Martin.

Nov 15 '05 #3
You could always hide all the controls since you can't hide the X only. Then put buttons on your form to make it minimize and maximize.
Nov 15 '05 #4
Yeah.

I was kind of hoping for something a little less stressful.

What I've decided to do is to remove the control box completely from 2 of my
forms (which really really need to be there all the time) and have the rest
available from the File Open menu (exception that Open when a window is
present simply restores it).

Bit naughty, but it works!

Thanks for the suggestion.

Iain
"Eric" <an*******@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
You could always hide all the controls since you can't hide the X only.

Then put buttons on your form to make it minimize and maximize.
Nov 15 '05 #5
> The MDI format suits the application I have built which has a number of
'management consoles'. I don't much care if MS do not approve! (I could
argue if pressed that they are each simply a view of the underlying
database). There appears no way of disabling only the close box. Certainly not without disabling the minimize and maximize.
Well... Maybe no .NET way. But since you are such a bad boy, not caring
about anything, you might as well do it through Win32. Here is the MFC way
to disable the close command (any menu options will automatically follow).

void CMainFrame::DisableClose()
{
CMenu* pMenu = GetSystemMenu(false);
pMenu->EnableMenuItem(SC_CLOSE, MF_DISABLED | MF_GRAYED);
}

void CMainFrame::EnableClose()
{
CMenu* pMenu = GetSystemMenu(false);
pMenu->EnableMenuItem(SC_CLOSE, MF_ENABLED);
}

Here a CMenu is used but this doesn't do much more than passing on the call
to a Win32 API function. It won't be hard to change the code to use WIn32
only. I won't help you doing it, I feel guilty enough as it is by providing
this information.
Even if I picked a hide rather than close option, I suspect I would still be unable to close the application. After all to hide the window I would have to cancel the close which seems to have the effect of cancelling the main
window close.

Any other thoughts?


No, still the same thought. You are abusing MDI and you are being served
right by the trouble you are getting yourself into doing so. Design
guidelines are not only there to protect the user, most of the time they
also protect the developer.

Really, it's for your own good :-).

Martin.
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jon | last post by:
I am writing an MDI app that uses a document manager class to keep track of opened child windows. I want the user to be able to close a child window, but then re-open the window from the "Window"...
2
by: Jon | last post by:
I am writing an MDI app that uses a document manager class to keep track of opened child windows. I want the user to be able to close a child window, but then re-open the window from the "Window"...
6
by: Edwinah63 | last post by:
Hi everyone, could someone give me some thoughts on the best way to manage mdi parent and child forms? in vb6 i could scroll through the forms collection and determine which forms were...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
2
by: Simon | last post by:
I setup a Midi & Child form I can open the child form and display info from a Text file I need to enable the user to change info on the child form and when closed write the text file back to...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
12
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
0
by: Rotsey | last post by:
Hi, I have a MDI form with child forms and a Window menu. When a new child form is created or closed I want to update the menu with a item for the child window. Problem is I have it adding...
6
by: SAL | last post by:
Hi, VS2005 post I'm opening a window using the following syntax: Protected Sub lbEstValue_Click(ByVal sender As Object, ByVal e As System.EventArgs)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.