VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Disable 'X' on Forms (Including MDI Child Forms)

by Mark Troutwine (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (14 Votes)

This is shorter way to disable the 'X' or close button on a form. It also works on MDI Child forms also which I have found most other code does not.

Inputs
None.
Assumes
Just copy and paste it as stated below!
Code Returns
None.
Side Effects
None.
API Declarations
' Place this in a module:
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Const SC_CLOSE = &HF060&
Public Const MF_BYCOMMAND = &H0&

Rate Disable 'X' on Forms (Including MDI Child Forms)

' Place this in the Form Load event of the form you want to disable the 'X':
Dim hSysMenu As Long
hSysMenu = GetSystemMenu(hwnd, False)
RemoveMenu hSysMenu, SC_CLOSE, MF_BYCOMMAND

Download this snippet    Add to My Saved Code

Disable 'X' on Forms (Including MDI Child Forms) Comments

No comments have been posted about Disable 'X' on Forms (Including MDI Child Forms). Why not be the first to post a comment about Disable 'X' on Forms (Including MDI Child Forms).

Post your comment

Subject:
Message:
0/1000 characters