ChiMai > 07-08-16, 12:04 AM
cpucloi > 07-08-16, 01:11 PM
ChiMai > 07-08-16, 02:52 PM
maidinhdan > 07-08-16, 04:34 PM
(07-08-16, 12:04 AM)ChiMai Đã viết: Khi em muốn cho 1 form hiện ra nhưng em không muốn cho người ta tắt cửa sổ này bằng nút cửa sổ Close và phải chọn nút mà em tạo ra để đóng form ạ? Em nhờ mọi người viết cho em đoạn code như vậy!?
(07-08-16, 02:52 PM)ChiMai Đã viết: em không hiểu cách sử dụng như thế nào?
Mã PHP:Sub EnabledClose()
Application.CommandBars.ActiveMenuBar.Controls("File").Controls("Close").Enabled = False
End Sub
Mã PHP:Sub DisablesClose()
Application.CommandBars.ActiveMenuBar.Controls("File").Controls("Close").Enabled = True
End Sub
Đoạn này em không hiểu: Controls("File").Nó là tên file ạ?
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Đóng form hả ông nội?", vbYesNo) = vbYes Then
Exit Sub
Else
Cancel = True
End If
End Sub
Option Compare Database
Option Explicit
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias _
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As _
Long, lpMenuItemInfo As MENUITEMINFO) As Long
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&
Public Property Get Enabled() As Boolean
Dim hwnd As Long
Dim hMenu As Long
Dim Result As Long
Dim MI As MENUITEMINFO
MI.cbSize = Len(MI)
MI.dwTypeData = String(80, 0)
MI.cch = Len(MI.dwTypeData)
MI.fMask = MF_GRAYED
MI.wID = SC_CLOSE
hwnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hwnd, 0)
Result = GetMenuItemInfo(hMenu, MI.wID, 0, MI)
Enabled = (MI.fState And MF_GRAYED) = 0
End Property
Public Property Let Enabled(boolClose As Boolean)
Dim hwnd As Long
Dim wFlags As Long
Dim hMenu As Long
Dim Result As Long
hwnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hwnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If
Result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Property
Option Compare Database
Option Explicit
Function InitApplication(intEnab As Boolean)
On Error GoTo err_proc
'Enabled or disables the MS application close (X) button - Dependant on state of intEnab
'Uses Class Module 'Close Command'
Const C_PROC_NAME = "InitApplication"
Dim C As CloseCommand
Set C = New CloseCommand
C.Enabled = intEnab
exit_proc:
Exit Function
err_proc:
MsgBox "Error in Function: '" & C_PROC_NAME & "'" & Chr(13) & Err.Description
Resume exit_proc
End Function