This code shows how to disable the X-button on a form, to keep the user from closing a form that wa
This code shows how to disable the X-button on a form, to keep the user from closing a form that way. Ok, now I hear you saying that this can
Rate This code shows how to disable the X-button on a form, to keep the user from closing a form that wa
(1(1 Vote))
MyForm is the name of the form you want to disable the X-button on.
Put the following code in a bas module
'//*********************************//'
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu 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 Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_DISABLED = &H2&
Public Sub DisableX(Frm As Form)
Dim hMenu As Long, nCount As Long
'Get handle to system menu
hMenu = GetSystemMenu(Frm.hwnd, 0)
'Get number of items in menu
nCount = GetMenuItemCount(hMenu)
'Remove last item from system menu (last item is 'Close')
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
'Redraw menu
DrawMenuBar Frm.hwnd
End Sub
This code shows how to disable the X-button on a form, to keep the user from closing a form that wa Comments
No comments yet — be the first to post one!
Post a Comment