Disable MDI child close button

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 6
Reputation: smgtreker is an unknown quantity at this point 
Solved Threads: 0
smgtreker smgtreker is offline Offline
Newbie Poster

Disable MDI child close button

 
0
  #1
Mar 2nd, 2005
Hi, I would really appreciate some help with disabling the close button (and the system menu's close option) of a MDI child form in C++ .NET. I've scoured the web, and although I can find it in VB .NET, and bits in C#, I can't find anything to help with c++. A step by step guide would be really appreciated as I guess this will involve some API programming, which I have no experience in.
Thanks very much to anyone that can help.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 6
Reputation: smgtreker is an unknown quantity at this point 
Solved Threads: 0
smgtreker smgtreker is offline Offline
Newbie Poster

Re: Disable MDI child close button

 
0
  #2
Mar 8th, 2005
After HOURS and HOURS of trying to fix this, I think I have finally come up with a solution for c++ .NET ! The issue you will notice with my code is that it has been placed in the VisibleChanged and sizechanged functions, instead of the Load function. this is because when visibility is changed on the form, for some reason the buttons were reset. I solved this obviously by activating the remove button function, whenever the form is becoming visible, or sized.

The code is as follows:

1. At the beginning of the file, include this header file:
#include "windows.h"

2. Add an event handler for when the visiblility and size is changed.

3. Add a function with the following code:

if(this->Visible)
{
HMENU test = GetSystemMenu((HWND)this->Handle.ToInt32(), false);
EnableMenuItem(test, SC_CLOSE, MF_GRAYED | MF_BYCOMMAND);
//the values you pass into RemoveMenu are from the file WinUser.h
}

4. Add to event handlers a call to the function above!

5. Thats It!

If anyone can see any improvement to the code, then please go ahead and post it! I added the call to the function, so that the close button would remain disabled, even when the MDI child is maximized.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2
Reputation: Lilleman is an unknown quantity at this point 
Solved Threads: 0
Lilleman Lilleman is offline Offline
Newbie Poster

Re: Disable MDI child close button

 
0
  #3
Feb 12th, 2007
One easy way of disable the close button (X) in a form is to create a "base form" that your other form inherits from and in the base form add this code:

Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
'This Greys out the X and stops close from appearing in the
'Control box on the form
Dim cp As CreateParams = MyBase.CreateParams
Const CS_DBLCLKS As Int32 = &H8
Const CS_NOCLOSE As Int32 = &H200
cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
Return cp
End Get
End Property
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC