Tipp 0212 UserForm ohne Titelleiste anzeigen
Autor/Einsender:
Datum:
  Angie
28.03.2002
Entwicklungsumgebung:   Excel 97
Mit Hilfe einiger API-Funktionen lässt sich auch eine UserForm ohne Titelleiste dazustellen. Damit diese UserForm dann auch mit der Maus verschoben werden kann, muss man der UserForm einen Klick auf die nicht mehr vorhandene Titelleiste vorgaukeln, wenn der Anwender auf eine beliebige freie Stelle im Formular klickt.
Code im Codebereich der UserForm
 
Option Explicit

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

Private Declare Function SendMessage Lib "user32" Alias _
      "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
      ByVal wParam As Long, lParam As Any) As Long

Private Declare Function ReleaseCapture Lib "user32" () As Long

Private Const GWL_STYLE As Long = -16
Private Const WS_CAPTION As Long = &HC00000

Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private hWndForm As Long
Private bCaption As Boolean

Private Sub UserForm_Initialize()
  If Val(Application.Version) >= 9 Then
    hWndForm = FindWindow("ThunderDFrame", Me.Caption)
  Else
    hWndForm = FindWindow("ThunderXFrame", Me.Caption)
  End If

  bCaption = False
  SetUserFormStyle
End Sub

Private Sub SetUserFormStyle()
  Dim frmStyle As Long

  If hWndForm = 0 Then Exit Sub

  frmStyle = GetWindowLong(hWndForm, GWL_STYLE)

  If bCaption Then
    frmStyle = frmStyle Or WS_CAPTION
  Else
    frmStyle = frmStyle And Not WS_CAPTION
  End If

  SetWindowLong hWndForm, GWL_STYLE, frmStyle

  DrawMenuBar hWndForm
End Sub

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal _
        Shift As Integer, ByVal X As Single, ByVal Y As Single)

  If hWndForm = 0 Then Exit Sub

  If Button = 1 Then
     ReleaseCapture
     SendMessage hWndForm, WM_NCLBUTTONDOWN, HTCAPTION, 0
  End If
End Sub

Private Sub optCaptionOn_Click()
  bCaption = True
  SetUserFormStyle
End Sub

Private Sub optCaptionOff_Click()
  bCaption = False
  SetUserFormStyle
End Sub
 
Links zum Thema
UserForm minimieren/maximieren
UserForm mit Icon in der Titelleiste
UserForm Schließen-Schaltfläche deaktivieren
UserForm Schließen-Schaltfläche entfernen
UserForm ungebunden anzeigen
UserForm verschieben verhindern
Hinweis
Die im Download befindliche *.frm-Datei kann für Word und PowerPoint im jeweiligen Programm im VB-Editor importiert werden.

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
Anwendung/VBA-Version
Access 97
Access 2000
Access XP
Access 2003
Access 2007
Access 2010
Excel 97
Excel 2000
Excel XP
Excel 2003
Excel 2007
Excel 2010
Word 97
Word 2000
Word XP
Word 2003
Word 2007
Word 2010
PPT 97
PPT 2000
PPT XP
PPT 2003
PPT 2007
PPT 2010
Outlook 97
Outlook 2000
Outlook XP
Outlook 2003
Outlook 2007
Outlook 2010


Download  (15,6 kB) Downloads bisher: [ 1827 ]

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, 31. Mai 2011