Important alert: (current site time 7/15/2013 8:47:42 AM EDT)
 

VB icon

_ Disable the X button on your form, or another Windows form at run-time (with HWND) _

Email
Submitted on: 8/10/2002 4:06:07 PM
By: Jon Barker  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB.NET
Views: 24196
(About the author)
 
     This code will disable the X button on any form you know the HWND (unique number) for. To test this code on your own application, provide the function with ActiveForm.Handle().ToInt32()

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: _ Disable the X button on your form, or another Windows form at run-time (with HWND)_
// Description:This code will disable the X button on any form you know the HWND (unique number) for.
To test this code on your own application, provide the function with ActiveForm.Handle().ToInt32()
// By: Jon Barker
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=469&lngWId=10//for details.//**************************************

Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
 Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Public Const SC_CLOSE = &HF060&
Public Const MF_BYCOMMAND = &H0&
Function RemoveXButton(ByVal iHWND As Integer) As Integer
Dim iSysMenu As Integer
iSysMenu = GetSystemMenu(iHWND, False)
Return RemoveMenu(iSysMenu, SC_CLOSE, MF_BYCOMMAND)
 End Function
'Disable the button on the current form:
RemoveXButton(ActiveForm.Handle().ToInt32())
'Thats it! tHe_cLeanER ownz you...


Other 14 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/10/2002 9:36:08 PMThe New iSoftware Company!

Is there a way to reverse this process? I would like to rewrite this as a boolean.
(If this comment was disrespectful, please report it.)

 
8/11/2002 4:24:48 AMtHe_cLeanER

Hi there iSoftware, i cant work out how to do it, but can give you the API calls i think would work:

===========================
Private Declare Function InsertMenuItem Lib
(If this comment was disrespectful, please report it.)

 
8/11/2002 4:32:26 AMtHe_cLeanER

eh? that didnt come out very well...
(If this comment was disrespectful, please report it.)

 
11/15/2002 11:54:11 PM

ahh?
Is it just me or is this code bugged?
(If this comment was disrespectful, please report it.)

 
3/13/2003 3:00:27 AM

The code can work. Just figure out. But you must change a bit here and there. This is how it goes.

Just change the ActiveForm.Handle().ToInt32() to Me.Handle().ToInt32()

Then the rest of the code put in a single module. Any more problem. Feel free to email me. Hope that helps.
(If this comment was disrespectful, please report it.)

 
5/10/2003 9:52:04 AMwhiteknight

hwnd in the declare should be a type intptr not an integer then you dont have to change Me.Handle.toInt32()
(If this comment was disrespectful, please report it.)

 
6/13/2003 11:25:02 AMDanny J

Hey, I'm moving into .NET, and that's ALOT more easier than the normal VB.
(If this comment was disrespectful, please report it.)

 
10/10/2005 9:00:46 PMJust some Coder

Why not do it the dot net way with

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
(If this comment was disrespectful, please report it.)

 
3/9/2006 9:31:33 PMfadi

thanks
(If this comment was disrespectful, please report it.)

 
3/20/2006 10:40:11 AMyusri

thank
(If this comment was disrespectful, please report it.)

 
1/30/2007 9:29:20 AMk.k.thirumoorthi

Lot of coding in Dot net,which is useful for me.
so i want DayaGrid Updating and Adding Row with vb.net coding only.
(If this comment was disrespectful, please report it.)

 
1/30/2007 9:29:42 AMk.k.thirumoorthi

Lot of coding in Dot net,which is useful for me.
so i want DataGrid Updating and Adding Row with vb.net coding only.
(If this comment was disrespectful, please report it.)

 
7/28/2007 2:39:58 PMSanchit Karve

DeleteMenu() API would work too.
(If this comment was disrespectful, please report it.)

 
7/28/2007 2:43:19 PMSanchit Karve

DeleteMenu() API would work too.
But if you plan to reverse the process, RemoveMenu() should be used.
(If this comment was disrespectful, please report it.)

 
9/1/2008 12:49:24 PMAxel

Nice men.
(If this comment was disrespectful, please report it.)

 
11/22/2008 12:20:42 AMsayareh

Hi
(If this comment was disrespectful, please report it.)

 
1/2/2009 2:08:00 AMsumit

hi
(If this comment was disrespectful, please report it.)

 
4/8/2009 3:29:12 PMmayank agrawal

very good site for providing project ideas
(If this comment was disrespectful, please report it.)

 
9/17/2009 4:32:19 AM

zabardust
(If this comment was disrespectful, please report it.)

 
9/12/2011 2:57:18 PM

this is really useful
this is the crreative mind
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.