VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Disable X button on form

by Petko Petkov (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

_Disable X button on form

Rate Disable X button on form

Private Declare Function GetSystemMenu 
Lib "user32" (ByVal hwnd As 
Long, ByVal bRevert 
As Long) As Long

Private Declare Function GetMenuItemCount 
Lib "user32" (ByVal hMenu As Long) As Long

Private Declare Function RemoveMenu Lib 
"user32" (ByVal hMenu As 
Long, ByVal nPosition As 
Long, ByVal wFlags As 
Long) As Long

Private Declare Function DrawMenuBar Lib 
"user32" (ByVal hwnd As 
Long) As Long

Private Const MF_BYPOSITION = &H400&

Private Const MF_DISABLED = &H2& 

Public Sub DisableX(Frm As 
 Form)

 Dim hMenu As Long

 Dim nCount As Long

   hMenu = GetSystemMenu(Frm.hwnd, 0)

   nCount = GetMenuItemCount(hMenu)

   Call RemoveMenu(hMenu, nCount - 1, 
 MF_DISABLED Or MF_BYPOSITION)

   DrawMenuBar Frm.hwnd

 End Sub


Private Sub Command1_Click()

   DisableX Me

 End Sub

Download this snippet    Add to My Saved Code

Disable X button on form Comments

No comments have been posted about Disable X button on form. Why not be the first to post a comment about Disable X button on form.

Post your comment

Subject:
Message:
0/1000 characters