Tipp 0379 Min- und Max-Button zur Laufzeit entfernen
Autor/Einsender:
Datum:
  Angie
14.01.2004
Entwicklungsumgebung:   VB 6
Bei der MDI-Form ist im Gegensatz zur "normalen" Form, bei der man den Min- und/oder den Max-Button über die entsprechenden Eigenschaften BorderStyle, Min- und MaxButton entfernen kann, das Entfernen dieser Buttons nicht so ohne weiteres möglich.
Mit den entsprechenden API-Funktionen lässt sich dies jedoch bewerkstelligen. Zuerst werden die Min- und Max-Buttons entfernt, und anschließend aus dem Systemmenü die Menüelemente Maximieren, Minimieren, Verschieben und Wiederherstellen.
Übrigens, der folgende Code kann auch bei jeder "normalen" VB-Form verwendet werden.
 
Option Explicit

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 Declare Function RemoveMenu Lib "user32" (ByVal hMenu _
      As Long, ByVal nPosition As Long, ByVal wFlags As Long) _
      As Long

Private Declare Function GetMenuItemCount Lib "user32" (ByVal _
      hMenu As Long) As Long

Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd _
      As Long) As Long

Private Const GWL_STYLE = (-16)

Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_THICKFRAME = &H40000

Private Const SC_CLOSE = &HF060
Private Const SC_MAXIMIZE = &HF030
Private Const SC_MINIMIZE = &HF020
Private Const SC_MOVE = &HF010
Private Const SC_RESTORE = &HF120

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

Public Sub SetFormStyle(ByVal frm As Object)
  Dim nStyle  As Long
  Dim nMenu   As Long
  Dim nCount  As Long

  With frm
    nStyle = GetWindowLong(.hWnd, GWL_STYLE)
    nStyle = nStyle And Not (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX _
           Or WS_THICKFRAME)
    SetWindowLong .hWnd, GWL_STYLE, nStyle

    nMenu = GetSystemMenu(.hWnd, 0)

    RemoveMenu nMenu, SC_MAXIMIZE, MF_REMOVE Or MF_BYCOMMAND
    RemoveMenu nMenu, SC_MINIMIZE, MF_REMOVE Or MF_BYCOMMAND
    RemoveMenu nMenu, SC_MOVE, MF_REMOVE Or MF_BYCOMMAND
    RemoveMenu nMenu, SC_RESTORE, MF_REMOVE Or MF_BYCOMMAND

    nCount = GetMenuItemCount(nMenu)
    RemoveMenu nMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION
    DrawMenuBar .hWnd
  End With
End Sub
 
Weitere Links zum Thema
Schließen-Schaltfläche deaktivieren

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (3,7 kB) Downloads bisher: [ 974 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Dienstag, 7. Juni 2011