Tipp 10.10 - BorderStyle ändern
Wie kann ich die BorderStyle-Eigenschaft einer Form zur Laufzeit ändern?
Mit dieser Funktion können Sie die BorderStyle-Eigenschaft einer Form zur Laufzeit ändern. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.
Verwendete Win32-Api-Aufrufe und Typen: SetWindowPos, SetWindowLong, GetWindowLong
Beispiel:
Option Explicit Private Const GWL_STYLE As Long = (-16&) Private Const GWL_EXSTYLE As Long = (-20&) Private Const WS_THICKFRAME As Long = &H40000 Private Const WS_MINIMIZEBOX As Long = &H20000 Private Const WS_MAXIMIZEBOX As Long = &H10000 Private Const WS_EX_TOOLWINDOW As Long = &H80& Private Const SWP_NOSIZE As Long = &H1 Private Const SWP_NOMOVE As Long = &H2 Private Const SWP_NOZORDER As Long = &H4 Private Const SWP_FRAMECHANGED As Long = &H20 Private Declare Function SetWindowPos Lib "user32" _ (ByVal hwnd As Long, _ ByVal hWndInsertAfter As Long, _ ByVal x As Long, _ ByVal y As Long, _ ByVal cx As Long, _ ByVal cy As Long, _ ByVal wFlags 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 GetWindowLong Lib "user32" Alias _ "GetWindowLongA" _ (ByVal hwnd As Long, _ ByVal nIndex As Long) As Long Public Enum BorderStyles Fixed = 1 Tool = 2 Sizeable = 3 End Enum Public Sub ToogleBorderStyle(lhWnd As Long, _ lStyle As BorderStyles) '// -------------------------------------------------------- '// Funktion: |Zwischen verschiedenen Formstilen '// |umschalten (BorderStyles) '// -------------------------------------------------------- '// Parameter: |lhWnd = gültiges Handle zu einem Fenster '// |lStyle = Wert aus dem Enum BorderStyles '// -------------------------------------------------------- '// Beispielaufruf in einer Form: '// 1. Aufruf: Umschalten von Sizeable in Fixed: '// ToogleBorderStyle hwnd, Fixed '// 2. Aufruf: Umschalten von Fixed in Sizeable '// ToogleBorderStyle hwnd, Fixed '// -------------------------------------------------------- '// Autor: | Stefan Kulpa '// | EDV Innovation & Consulting - Dormagen '// -------------------------------------------------------- Dim bToggleStyle As Boolean Dim bToggleExStyle As Boolean Select Case lStyle Case Fixed: bToggleStyle = True Case Tool: bToggleExStyle = True Case Sizeable: bToggleExStyle = True bToggleStyle = True End Select If bToggleStyle Then '// ---------------------------------------------------- '// Reguläre Style-Bits setzen. In diesem Fall zwischen '// Fixed und Sizeable hin- und herschalten. '// ---------------------------------------------------- Call SetWindowLong(lhWnd, _ GWL_STYLE, _ GetWindowLong(lhWnd, GWL_STYLE) _ Xor (WS_THICKFRAME Or _ WS_MINIMIZEBOX Or _ WS_MAXIMIZEBOX)) End If If bToggleExStyle Then '// ---------------------------------------------------- '// Erweiterte Style-Bits setzen. In diesem Fall '// zwischen Tool und Sizeable hin- und herschalten. '// ---------------------------------------------------- Call SetWindowLong(lhWnd, _ GWL_EXSTYLE, _ GetWindowLong(lhWnd, _ GWL_EXSTYLE) _ Xor WS_EX_TOOLWINDOW) End If '// -------------------------------------------------------- '// Form neu zeichnen '// -------------------------------------------------------- Call SetWindowPos(lhWnd, 0&, 0&, 0&, 0&, 0&, _ SWP_NOMOVE Or _ SWP_NOSIZE Or _ SWP_NOZORDER Or _ SWP_FRAMECHANGED) End Sub