Randy Birch's Beispiel
RemoveMenu: Killing the Form's Close Menu and 'X' Button
('X' im Systemmenü deaktivieren)

Das sieht dann so aus:

für VBA adaptiert:


Option Explicit

Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000

Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
   ByVal bRevert 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 FindWindow Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub UserForm_Initialize()
   Dim hMenu As Long
   Dim menuItemCount As Long
   Dim hWnd_UF As Long
   
   hWnd_UF = FindWindow("ThunderDFrame", Me.Caption)
   
   'Obtain the handle to the form's system menu
   hMenu = GetSystemMenu(hWnd_UF, 0)
   
   If hMenu Then
      'Obtain the number of items in the menu
      menuItemCount = GetMenuItemCount(hMenu)
      
      'Remove the system menu Close menu item.
      'The menu item is 0-based, so the last
      'item on the menu is menuItemCount - 1
      RemoveMenu hMenu, menuItemCount - 1, MF_REMOVE Or MF_BYPOSITION
      
      'Remove the system menu separator line
      RemoveMenu hMenu, menuItemCount - 2, MF_REMOVE Or MF_BYPOSITION
      
      'Force a redraw of the menu. This
      'refreshes the titlebar, dimming the X
      DrawMenuBar hWnd_UF
   End If
End Sub


 Um das Beispiel auszuprobieren, den Code komplett in eine Userform kopieren.

Zum Seitenanfang