README.md

December 4, 2022 · View on GitHub

_Disable X button on form

Description

_Disable X button on form

More Info

Submitted On
ByPetko Petkov
LevelIntermediate
User Rating5.0 (30 globes from 6 users)
CompatibilityVB 6.0
CategoryCustom Controls/ Forms/ Menus
WorldVisual Basic
Archive File

Source Code

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