-
Hi...
I'm trying to disable the 'x' close button in an mdi form when it's maximised... See.. in word when you maximise your document, there are 2 'x' close buttons one over the other one... so I need to disable or hide the document one... Hope you all see what I mean!
Thanks.
keetsh
-
Use the following code to disable a "X" (Close) button on a form:
Code:
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Private Const MF_BYCOMMAND = &H0&
Private Const MF_GRAYED = &H1&
Private Const MF_ENABLED = &H0&
Private Const SC_CLOSE = &HF060&
Private Const FOOLVB = -10
Sub DisableMenu(form As form)
ModifyMenu GetSystemMenu(form.hwnd, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED, FOOLVB, "Close"
End Sub
Sub EnableMenu(form As form)
ModifyMenu GetSystemMenu(form.hwnd, 0), SC_CLOSE, MF_BYCOMMAND Or MF_ENABLED, SC_CLOSE, "Close"
End Sub
-
Code:
'this goes in a module
Public Declare Function GetMenuItemCount _
Lib "user32" (ByVal hMenu As Long) As _
Long
Public Declare Function GetSystemMenu Lib _
"user32" (ByVal hwnd As Long, ByVal _
bRevert 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_REMOVE = &H1000&
Public Const MF_INSERT = &H0&
Public Const MF_ENABLED = &H0&
Public Const MF_BYPOSITION = &H400&
Public Sub DisableX(frm As Form, blnDisabled As Boolean)
Dim hMenu As Long
Dim nCount As Long
If blnDisabled = True Then
hMenu = GetSystemMenu(frm.hwnd, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)
DrawMenuBar frm.hwnd
Else
hMenu = GetSystemMenu(frm.hwnd, True)
DrawMenuBar frm.hwnd
End If
End Sub
'this goes in form_load
Call DisableX(Me, True)
if thats a little too complicated, go to http://www.geocities.com/sfprogrammers
and download it in the visual basic section.
-
It also will not work, because that will make everything (Min, Max and Close) invisible instead of grayed.