Disable [X] button on form
More of a Snippet of code with a example project
Easy to follow.
Code:
' Description:This code will disable the [x] button on any form you know the HWND for
' By: NextGen1 of Mpgh.net
' This code is copyrighted and comes with no warranties.
' This code is intended for demonstration and all rights are granted soley to mpgh.net and it's members
' If you require any further information please contact me at mpgh.net via PM (Get an account if you don't have one)
' Tutorials and apps create by me for mpgh.net will contain the following agreement
' By adding this code in whole or part to any existing or new application you agree to the following terms
' You agree to keep these notes connected with this code.
' You agree to grant credit to it's source (Mpgh.net)
' You agree to keep this note in whole without edit inside of your code
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const MF_ DISABLED = &H2
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean
Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
Dim hMenu As IntPtr
Dim menuItemCount As Integer
hMenu = GetSystemMenu(hwnd, False)
menuItemCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, menuItemCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call RemoveMenu(hMenu, menuItemCount - 2, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(hwnd)
End Sub
This part disables the [x] Button
Code:
' Call disable , Examples: on button click , on load, wherever you want it.
DisableCloseButton(Me.Handle)
Screen Shots
[IMG]https://i111.photobucke*****m/albums/n121/golmor/disablexs1.png[/IMG]
[IMG]https://i111.photobucke*****m/albums/n121/golmor/disablexs2.png[/IMG]
Virus Scans
Source Code Scan
Sample Program Scan
Links
Source
Example
Note: Yes I just realized the linklabel says mpght.net it should be mpgh.net, however, it's a clickable link that takes you to mpgh.net
Note: You may need to make some minor changes to the code to match your controls and it's names