944,030 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 16740
  • ASP.NET RSS
Mar 2nd, 2005
0

Disable MDI child close button

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smgtreker is offline Offline
6 posts
since Feb 2005
Mar 8th, 2005
0

Re: Disable MDI child close button

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smgtreker is offline Offline
6 posts
since Feb 2005
Feb 12th, 2007
0

Re: Disable MDI child close button

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lilleman is offline Offline
2 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: listbox multiple selection
Next Thread in ASP.NET Forum Timeline: DTS to SSIS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC