1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Option Explicit
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) 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 Const MF_REMOVE = &H1000&
Private Const MF_BYPOSITION = &H400&
Private Const GWL_STYLE = (-16)
Private Const WS_THICKFRAME = &H40000
Private Const SC_MOVE = &HF010&
Private Const MF_BYCOMMAND = &H0&
Public Sub GestMenuSys(Frm As Form)
'==== Désactive les options de la case system =========================
Dim nStyle As Long
Dim nMenu As Long
Dim nCount As Long
Dim hMenu As Long
Dim menuItemCount As Long
'--- Désactive la case system "fermer" ----
hMenu = GetSystemMenu(Frm.hwnd, 0)
If hMenu Then
menuItemCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, menuItemCount - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(hMenu, menuItemCount - 2, MF_REMOVE Or MF_BYPOSITION)
Call DrawMenuBar(Frm.hwnd)
End If
'--- Empêche le déplacement ---
With Frm
nStyle = GetWindowLong(.hwnd, GWL_STYLE)
nStyle = nStyle And Not (WS_THICKFRAME)
SetWindowLong .hwnd, GWL_STYLE, nStyle
nMenu = GetSystemMenu(.hwnd, 0)
RemoveMenu nMenu, SC_MOVE, MF_REMOVE Or MF_BYCOMMAND
nCount = GetMenuItemCount(nMenu)
RemoveMenu nMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION
DrawMenuBar .hwnd
End With
Frm.BackColor = &HC0C0C0
End Sub |
Partager