Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1232to1236
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Steuersymbole auf UserForm anzeigen

Steuersymbole auf UserForm anzeigen
Pascal
Guten Tag miteinander
Ich habe dank diesem Forum ein Klassenmodul gefunden, mittels dem man einer UserForm oben rechts die Symbole für Maximieren, Minimieren und Schliessen geben kann:
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 ShowWindow Lib "user32" (ByVal _
hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare 

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

Function SetFocus Lib "user32" (ByVal _
hwnd As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_THICKFRAME As Long = &H40000
Private Const WS_SYSMENU As Long = &H80000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private m_objUserForm   As Object
Private m_hWndForm      As Long
Enum enuWinStat
Minimieren = vbMinimizedFocus
Normal = vbNormal
End Enum
Public Property Set Form(ByVal objForm As Object)
Dim nStyle As Long
Set m_objUserForm = objForm
m_hWndForm = FindWindow(vbNullString, m_objUserForm.Caption)
If m_hWndForm  0 Then
nStyle = GetWindowLong(m_hWndForm, GWL_STYLE)
nStyle = nStyle Or WS_THICKFRAME Or WS_SYSMENU Or WS_MINIMIZEBOX
SetWindowLong m_hWndForm, GWL_STYLE, nStyle
DrawMenuBar m_hWndForm
SetFocus m_hWndForm
End If
End Property
Public Property Let WinState_(Show_ As enuWinStat)
ShowWindow m_hWndForm, Show_
End Property
Diesen Code hab ich sauber in ein Klassenmodul gepackt.
Nun aber meine Frage:
Was muss ich in meiner UserForm1 noch einbauen, damit die Symbole (Minimieren, Maximieren,  _
Schliessen) auch oben rechts dargestellt werden ?
Habe das über folgenden Code Probiert, geht aber leider nicht:

Sub UserForm1_Activate()
'######## UserForm - Steuerung / Klassen --> Aktivierung der UserForm
Set objUserForm = New UserFormular_Steuerung
Set objUserForm.Form = Me
End Sub
Besten Dank für Eure Hilfe !

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
Test 64 bit
27.10.2011 10:20:45
Matthias
Hallo Tino
Hab mal getestet:
Win7 64 bit / XL2007
Minimieren und Schließen funktioniert.
Maximieren ist deaktiviert
Gruß Matthias
AW: Test 64 bit
27.10.2011 11:00:16
Tino
Hallo,
danke fürs testen!
Wenn man dies auch möchte, kan man den Code im Klassenmodul so erweitern.

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 ShowWindow Lib "user32" (ByVal _
      hwnd As Long, ByVal nCmdShow As Long) As Long

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

Private Declare Function SetFocus Lib "user32" (ByVal _
      hwnd As Long) As Long

Private Const GWL_STYLE As Long = (-16)
Private Const WS_THICKFRAME As Long = &H40000
Private Const WS_SYSMENU As Long = &H80000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000

Private m_objUserForm   As Object
Private m_hWndForm      As Long

Enum enuWinStat
    Minimieren = vbMinimizedFocus
    Normal = vbNormal
    Maximieren = vbMaximizedFocus
End Enum

Public Property Set Form(ByVal objForm As Object)
  Dim nStyle As Long

  Set m_objUserForm = objForm
  m_hWndForm = FindWindow(vbNullString, m_objUserForm.Caption)

  If m_hWndForm <> 0 Then
    nStyle = GetWindowLong(m_hWndForm, GWL_STYLE)

    nStyle = nStyle Or WS_THICKFRAME Or WS_SYSMENU Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX

    SetWindowLong m_hWndForm, GWL_STYLE, nStyle

    DrawMenuBar m_hWndForm
    SetFocus m_hWndForm
  End If
End Property

Public Property Let WinState_(Show_ As enuWinStat)
    ShowWindow m_hWndForm, Show_
End Property

Wenn man aus VBA in der Form dies machen will, würde ich objUserForm im Kopf deklarieren.

Dim objUserForm As UserFormular_Steuerung

Private Sub UserForm_Activate()
    Set objUserForm = New UserFormular_Steuerung
    Set objUserForm.Form = Me
End Sub

Private Sub UserForm_Terminate()
Set objUserForm = Nothing
End Sub

Private Sub CommandButton1_Click()
objUserForm.WinState_ = Minimieren
End Sub

Private Sub CommandButton2_Click()
objUserForm.WinState_ = Maximieren
End Sub
Gruß Tino
Anzeige
AW: Steuersymbole auf UserForm anzeigen
27.10.2011 12:20:36
Pascal
Hi !
Herzlichen dank für dieses Beispiel von Dir. Dieses funktiniert einwandfrei.
Aber ... obwohl ich auf meiner Userform1 auch den genau gleichen Code setzte (analog Deiner Userform1, plus noch meine Commandbuttons, Listboxen etc....) funzt meine Userform1 nicht.
Bloss Deine funktioniert einwandfrei.
Woran das liegen mag ? Hmmmmm .....

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige