Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
Dim AuthorizedExit As Boolean
Private Sub Command1_Click()
AuthorizedExit = True
Unload Me
End Sub
Private Sub Form_Load()
AuthorizedExit = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not AuthorizedExit Then Cancel = True
End Sub
Disable the X (close button) on the title bar
This tip shows you how to disable the X on the title bar of you forms. It does this by removing the close item in the form's system menu. This works fine, until you want to re-enable the X.
Declarations
Paste this into the declaration section:
Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&
Form Code
Then paste this into the form:
Private Sub Form_Load()
Dim hSysMenu As Long
Dim nCnt As Long
'First, show the form
Me.Show
'Get handle to our form's system menu
'(Restore, Maximize, Move, close etc.)
hSysMenu = GetSystemMenu(Me.hwnd, False)
If hSysMenu Then
'Get System menu's menu count
nCnt = GetMenuItemCount(hSysMenu)
If nCnt Then
'Menu count is based on 0 (0, 1, 2, 3...)
RemoveMenu hSysMenu, nCnt - 1, _
MF_BYPOSITION Or MF_REMOVE
RemoveMenu hSysMenu, nCnt - 2, _
MF_BYPOSITION Or MF_REMOVE 'Remove the seperator
DrawMenuBar Me.hwnd
'Force caption bar's refresh. Disabling X button
Me.Caption = "Try to close me!"
End If
End If
End Sub
Private Declare Function [COLOR=blue]GetSystemMenu Lib "User32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long[/color]
Private Declare Function [COLOR=green]RemoveMenu Lib "User32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long[/color]
Private Const MF_BYPOSITION = &H400
Private Sub Form_Load()
[COLOR=green]RemoveMenu [COLOR=blue]GetSystemMenu(Me.hWnd, 0)[/color], 6, MF_BYPOSITION[/color]
End Sub
hMenu = [COLOR=blue]GetSystemMenu(Me.hWnd, 0)[/color]
[COLOR=green]RemoveMenu hMenu, 6, MF_BYPOSITION[/color]
MSDN said:If the bRevert parameter is FALSE, the return value is a handle to a copy of the window menu
MSDN said:Parameters
hMenu
Handle to the menu to be changed.
uPosition
Specifies the menu item to be deleted, as determined by the uFlags parameter.
uFlags
Specifies how the uPosition parameter is interpreted. This parameter must be one of the following values.
MF_BYCOMMAND
Indicates that uPosition gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified, the MF_BYCOMMAND flag is the default flag.
MF_BYPOSITION
Indicates that uPosition gives the zero-based relative position of the menu item.