Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const SC_CLOSE As Long = &HF060
Private Const WS_SYSMENU As Long = &H80000
Public Sub MinMax(sCaption As String, Optional HideMenu As Boolean = True)
Dim hWndForm As Long
Dim hMenu As Long
Dim iStyle As Long
hWndForm = FindWindow(vbNullString, sCaption)
If HideMenu Then
iStyle = GetWindowLong(hWndForm, GWL_STYLE)
iStyle = iStyle And Not WS_SYSMENU
SetWindowLong hWndForm, GWL_STYLE, iStyle
Else
hMenu = GetSystemMenu(hWndForm, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
End If
End Sub